@turf/transform-scale 7.0.0-alpha.2 → 7.0.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 +4 -9
- package/dist/cjs/index.cjs +103 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +15 -0
- package/dist/esm/index.d.ts +15 -0
- package/dist/esm/index.js +103 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +43 -36
- package/dist/es/index.js +0 -148
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -161
- package/index.d.ts +0 -13
package/README.md
CHANGED
|
@@ -41,26 +41,21 @@ Returns **[GeoJSON][1]** scaled GeoJSON
|
|
|
41
41
|
|
|
42
42
|
[6]: 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-scale
|
|
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,103 @@
|
|
|
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 _clone = require('@turf/clone');
|
|
6
|
+
var _center = require('@turf/center');
|
|
7
|
+
var _centroid = require('@turf/centroid');
|
|
8
|
+
var _bbox = require('@turf/bbox');
|
|
9
|
+
var _rhumbbearing = require('@turf/rhumb-bearing');
|
|
10
|
+
var _rhumbdistance = require('@turf/rhumb-distance');
|
|
11
|
+
var _rhumbdestination = require('@turf/rhumb-destination');
|
|
12
|
+
var _meta = require('@turf/meta');
|
|
13
|
+
var _helpers = require('@turf/helpers');
|
|
14
|
+
var _invariant = require('@turf/invariant');
|
|
15
|
+
function transformScale(geojson, factor, options) {
|
|
16
|
+
options = options || {};
|
|
17
|
+
if (!_helpers.isObject.call(void 0, options))
|
|
18
|
+
throw new Error("options is invalid");
|
|
19
|
+
var origin = options.origin;
|
|
20
|
+
var mutate = options.mutate;
|
|
21
|
+
if (!geojson)
|
|
22
|
+
throw new Error("geojson required");
|
|
23
|
+
if (typeof factor !== "number" || factor <= 0)
|
|
24
|
+
throw new Error("invalid factor");
|
|
25
|
+
var originIsPoint = Array.isArray(origin) || typeof origin === "object";
|
|
26
|
+
if (mutate !== true)
|
|
27
|
+
geojson = _clone.clone.call(void 0, geojson);
|
|
28
|
+
if (geojson.type === "FeatureCollection" && !originIsPoint) {
|
|
29
|
+
_meta.featureEach.call(void 0, geojson, function(feature, index) {
|
|
30
|
+
geojson.features[index] = scale(feature, factor, origin);
|
|
31
|
+
});
|
|
32
|
+
return geojson;
|
|
33
|
+
}
|
|
34
|
+
return scale(geojson, factor, origin);
|
|
35
|
+
}
|
|
36
|
+
__name(transformScale, "transformScale");
|
|
37
|
+
function scale(feature, factor, origin) {
|
|
38
|
+
var isPoint = _invariant.getType.call(void 0, feature) === "Point";
|
|
39
|
+
origin = defineOrigin(feature, origin);
|
|
40
|
+
if (factor === 1 || isPoint)
|
|
41
|
+
return feature;
|
|
42
|
+
_meta.coordEach.call(void 0, feature, function(coord) {
|
|
43
|
+
var originalDistance = _rhumbdistance.rhumbDistance.call(void 0, origin, coord);
|
|
44
|
+
var bearing = _rhumbbearing.rhumbBearing.call(void 0, origin, coord);
|
|
45
|
+
var newDistance = originalDistance * factor;
|
|
46
|
+
var newCoord = _invariant.getCoords.call(void 0, _rhumbdestination.rhumbDestination.call(void 0, origin, newDistance, bearing));
|
|
47
|
+
coord[0] = newCoord[0];
|
|
48
|
+
coord[1] = newCoord[1];
|
|
49
|
+
if (coord.length === 3)
|
|
50
|
+
coord[2] *= factor;
|
|
51
|
+
});
|
|
52
|
+
delete feature.bbox;
|
|
53
|
+
return feature;
|
|
54
|
+
}
|
|
55
|
+
__name(scale, "scale");
|
|
56
|
+
function defineOrigin(geojson, origin) {
|
|
57
|
+
if (origin === void 0 || origin === null)
|
|
58
|
+
origin = "centroid";
|
|
59
|
+
if (Array.isArray(origin) || typeof origin === "object")
|
|
60
|
+
return _invariant.getCoord.call(void 0, origin);
|
|
61
|
+
var bbox = geojson.bbox ? geojson.bbox : _bbox.bbox.call(void 0, geojson, { recalculate: true });
|
|
62
|
+
var west = bbox[0];
|
|
63
|
+
var south = bbox[1];
|
|
64
|
+
var east = bbox[2];
|
|
65
|
+
var north = bbox[3];
|
|
66
|
+
switch (origin) {
|
|
67
|
+
case "sw":
|
|
68
|
+
case "southwest":
|
|
69
|
+
case "westsouth":
|
|
70
|
+
case "bottomleft":
|
|
71
|
+
return _helpers.point.call(void 0, [west, south]);
|
|
72
|
+
case "se":
|
|
73
|
+
case "southeast":
|
|
74
|
+
case "eastsouth":
|
|
75
|
+
case "bottomright":
|
|
76
|
+
return _helpers.point.call(void 0, [east, south]);
|
|
77
|
+
case "nw":
|
|
78
|
+
case "northwest":
|
|
79
|
+
case "westnorth":
|
|
80
|
+
case "topleft":
|
|
81
|
+
return _helpers.point.call(void 0, [west, north]);
|
|
82
|
+
case "ne":
|
|
83
|
+
case "northeast":
|
|
84
|
+
case "eastnorth":
|
|
85
|
+
case "topright":
|
|
86
|
+
return _helpers.point.call(void 0, [east, north]);
|
|
87
|
+
case "center":
|
|
88
|
+
return _center.center.call(void 0, geojson);
|
|
89
|
+
case void 0:
|
|
90
|
+
case null:
|
|
91
|
+
case "centroid":
|
|
92
|
+
return _centroid.centroid.call(void 0, geojson);
|
|
93
|
+
default:
|
|
94
|
+
throw new Error("invalid origin");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
__name(defineOrigin, "defineOrigin");
|
|
98
|
+
var turf_transform_scale_default = transformScale;
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
exports.default = turf_transform_scale_default; exports.transformScale = transformScale;
|
|
103
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"names":[],"mappings":"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","sourcesContent":["import { clone } from \"@turf/clone\";\nimport { center } from \"@turf/center\";\nimport { centroid } from \"@turf/centroid\";\nimport { bbox as turfBBox } from \"@turf/bbox\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { coordEach, featureEach } from \"@turf/meta\";\nimport { point, isObject } from \"@turf/helpers\";\nimport { getCoord, getCoords, getType } from \"@turf/invariant\";\n\n/**\n * Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger).\n * If a FeatureCollection is provided, the origin point will be calculated based on each individual Feature.\n *\n * @name transformScale\n * @param {GeoJSON} geojson GeoJSON to be scaled\n * @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.\n * @param {Object} [options={}] Optional parameters\n * @param {string|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} scaled GeoJSON\n * @example\n * var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * var scaledPoly = turf.transformScale(poly, 3);\n *\n * //addToMap\n * var addToMap = [poly, scaledPoly];\n * scaledPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformScale(geojson, factor, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var origin = options.origin;\n var mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson required\");\n if (typeof factor !== \"number\" || factor <= 0)\n throw new Error(\"invalid factor\");\n var originIsPoint = Array.isArray(origin) || typeof origin === \"object\";\n\n // Clone geojson to avoid side effects\n if (mutate !== true) geojson = clone(geojson);\n\n // Scale each Feature separately\n if (geojson.type === \"FeatureCollection\" && !originIsPoint) {\n featureEach(geojson, function (feature, index) {\n geojson.features[index] = scale(feature, factor, origin);\n });\n return geojson;\n }\n // Scale Feature/Geometry\n return scale(geojson, factor, origin);\n}\n\n/**\n * Scale Feature/Geometry\n *\n * @private\n * @param {Feature|Geometry} feature GeoJSON Feature/Geometry\n * @param {number} factor of scaling, positive or negative values greater than 0\n * @param {string|Coord} [origin=\"centroid\"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @returns {Feature|Geometry} scaled GeoJSON Feature/Geometry\n */\nfunction scale(feature, factor, origin) {\n // Default params\n var isPoint = getType(feature) === \"Point\";\n origin = defineOrigin(feature, origin);\n\n // Shortcut no-scaling\n if (factor === 1 || isPoint) return feature;\n\n // Scale each coordinate\n coordEach(feature, function (coord) {\n var originalDistance = rhumbDistance(origin, coord);\n var bearing = rhumbBearing(origin, coord);\n var newDistance = originalDistance * factor;\n var newCoord = getCoords(rhumbDestination(origin, newDistance, bearing));\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n if (coord.length === 3) coord[2] *= factor;\n });\n\n delete feature.bbox;\n\n return feature;\n}\n\n/**\n * Define Origin\n *\n * @private\n * @param {GeoJSON} geojson GeoJSON\n * @param {string|Coord} origin sw/se/nw/ne/center/centroid\n * @returns {Feature<Point>} Point origin\n */\nfunction defineOrigin(geojson, origin) {\n // Default params\n if (origin === undefined || origin === null) origin = \"centroid\";\n\n // Input Coord\n if (Array.isArray(origin) || typeof origin === \"object\")\n return getCoord(origin);\n\n // Define BBox\n var bbox = geojson.bbox\n ? geojson.bbox\n : turfBBox(geojson, { recalculate: true });\n var west = bbox[0];\n var south = bbox[1];\n var east = bbox[2];\n var north = bbox[3];\n\n switch (origin) {\n case \"sw\":\n case \"southwest\":\n case \"westsouth\":\n case \"bottomleft\":\n return point([west, south]);\n case \"se\":\n case \"southeast\":\n case \"eastsouth\":\n case \"bottomright\":\n return point([east, south]);\n case \"nw\":\n case \"northwest\":\n case \"westnorth\":\n case \"topleft\":\n return point([west, north]);\n case \"ne\":\n case \"northeast\":\n case \"eastnorth\":\n case \"topright\":\n return point([east, north]);\n case \"center\":\n return center(geojson);\n case undefined:\n case null:\n case \"centroid\":\n return centroid(geojson);\n default:\n throw new Error(\"invalid origin\");\n }\n}\n\nexport { transformScale };\nexport default transformScale;\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AllGeoJSON, Corners, Coord } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* http://turfjs.org/docs/#transformscale
|
|
5
|
+
*/
|
|
6
|
+
declare function transformScale<T extends AllGeoJSON>(
|
|
7
|
+
geojson: T,
|
|
8
|
+
factor: number,
|
|
9
|
+
options?: {
|
|
10
|
+
origin?: Corners | Coord;
|
|
11
|
+
mutate?: boolean;
|
|
12
|
+
}
|
|
13
|
+
): T;
|
|
14
|
+
|
|
15
|
+
export { transformScale as default, transformScale };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AllGeoJSON, Corners, Coord } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* http://turfjs.org/docs/#transformscale
|
|
5
|
+
*/
|
|
6
|
+
declare function transformScale<T extends AllGeoJSON>(
|
|
7
|
+
geojson: T,
|
|
8
|
+
factor: number,
|
|
9
|
+
options?: {
|
|
10
|
+
origin?: Corners | Coord;
|
|
11
|
+
mutate?: boolean;
|
|
12
|
+
}
|
|
13
|
+
): T;
|
|
14
|
+
|
|
15
|
+
export { transformScale as default, transformScale };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.js
|
|
5
|
+
import { clone } from "@turf/clone";
|
|
6
|
+
import { center } from "@turf/center";
|
|
7
|
+
import { centroid } from "@turf/centroid";
|
|
8
|
+
import { bbox as turfBBox } from "@turf/bbox";
|
|
9
|
+
import { rhumbBearing } from "@turf/rhumb-bearing";
|
|
10
|
+
import { rhumbDistance } from "@turf/rhumb-distance";
|
|
11
|
+
import { rhumbDestination } from "@turf/rhumb-destination";
|
|
12
|
+
import { coordEach, featureEach } from "@turf/meta";
|
|
13
|
+
import { point, isObject } from "@turf/helpers";
|
|
14
|
+
import { getCoord, getCoords, getType } from "@turf/invariant";
|
|
15
|
+
function transformScale(geojson, factor, options) {
|
|
16
|
+
options = options || {};
|
|
17
|
+
if (!isObject(options))
|
|
18
|
+
throw new Error("options is invalid");
|
|
19
|
+
var origin = options.origin;
|
|
20
|
+
var mutate = options.mutate;
|
|
21
|
+
if (!geojson)
|
|
22
|
+
throw new Error("geojson required");
|
|
23
|
+
if (typeof factor !== "number" || factor <= 0)
|
|
24
|
+
throw new Error("invalid factor");
|
|
25
|
+
var originIsPoint = Array.isArray(origin) || typeof origin === "object";
|
|
26
|
+
if (mutate !== true)
|
|
27
|
+
geojson = clone(geojson);
|
|
28
|
+
if (geojson.type === "FeatureCollection" && !originIsPoint) {
|
|
29
|
+
featureEach(geojson, function(feature, index) {
|
|
30
|
+
geojson.features[index] = scale(feature, factor, origin);
|
|
31
|
+
});
|
|
32
|
+
return geojson;
|
|
33
|
+
}
|
|
34
|
+
return scale(geojson, factor, origin);
|
|
35
|
+
}
|
|
36
|
+
__name(transformScale, "transformScale");
|
|
37
|
+
function scale(feature, factor, origin) {
|
|
38
|
+
var isPoint = getType(feature) === "Point";
|
|
39
|
+
origin = defineOrigin(feature, origin);
|
|
40
|
+
if (factor === 1 || isPoint)
|
|
41
|
+
return feature;
|
|
42
|
+
coordEach(feature, function(coord) {
|
|
43
|
+
var originalDistance = rhumbDistance(origin, coord);
|
|
44
|
+
var bearing = rhumbBearing(origin, coord);
|
|
45
|
+
var newDistance = originalDistance * factor;
|
|
46
|
+
var newCoord = getCoords(rhumbDestination(origin, newDistance, bearing));
|
|
47
|
+
coord[0] = newCoord[0];
|
|
48
|
+
coord[1] = newCoord[1];
|
|
49
|
+
if (coord.length === 3)
|
|
50
|
+
coord[2] *= factor;
|
|
51
|
+
});
|
|
52
|
+
delete feature.bbox;
|
|
53
|
+
return feature;
|
|
54
|
+
}
|
|
55
|
+
__name(scale, "scale");
|
|
56
|
+
function defineOrigin(geojson, origin) {
|
|
57
|
+
if (origin === void 0 || origin === null)
|
|
58
|
+
origin = "centroid";
|
|
59
|
+
if (Array.isArray(origin) || typeof origin === "object")
|
|
60
|
+
return getCoord(origin);
|
|
61
|
+
var bbox = geojson.bbox ? geojson.bbox : turfBBox(geojson, { recalculate: true });
|
|
62
|
+
var west = bbox[0];
|
|
63
|
+
var south = bbox[1];
|
|
64
|
+
var east = bbox[2];
|
|
65
|
+
var north = bbox[3];
|
|
66
|
+
switch (origin) {
|
|
67
|
+
case "sw":
|
|
68
|
+
case "southwest":
|
|
69
|
+
case "westsouth":
|
|
70
|
+
case "bottomleft":
|
|
71
|
+
return point([west, south]);
|
|
72
|
+
case "se":
|
|
73
|
+
case "southeast":
|
|
74
|
+
case "eastsouth":
|
|
75
|
+
case "bottomright":
|
|
76
|
+
return point([east, south]);
|
|
77
|
+
case "nw":
|
|
78
|
+
case "northwest":
|
|
79
|
+
case "westnorth":
|
|
80
|
+
case "topleft":
|
|
81
|
+
return point([west, north]);
|
|
82
|
+
case "ne":
|
|
83
|
+
case "northeast":
|
|
84
|
+
case "eastnorth":
|
|
85
|
+
case "topright":
|
|
86
|
+
return point([east, north]);
|
|
87
|
+
case "center":
|
|
88
|
+
return center(geojson);
|
|
89
|
+
case void 0:
|
|
90
|
+
case null:
|
|
91
|
+
case "centroid":
|
|
92
|
+
return centroid(geojson);
|
|
93
|
+
default:
|
|
94
|
+
throw new Error("invalid origin");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
__name(defineOrigin, "defineOrigin");
|
|
98
|
+
var turf_transform_scale_default = transformScale;
|
|
99
|
+
export {
|
|
100
|
+
turf_transform_scale_default as default,
|
|
101
|
+
transformScale
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"sourcesContent":["import { clone } from \"@turf/clone\";\nimport { center } from \"@turf/center\";\nimport { centroid } from \"@turf/centroid\";\nimport { bbox as turfBBox } from \"@turf/bbox\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { coordEach, featureEach } from \"@turf/meta\";\nimport { point, isObject } from \"@turf/helpers\";\nimport { getCoord, getCoords, getType } from \"@turf/invariant\";\n\n/**\n * Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger).\n * If a FeatureCollection is provided, the origin point will be calculated based on each individual Feature.\n *\n * @name transformScale\n * @param {GeoJSON} geojson GeoJSON to be scaled\n * @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.\n * @param {Object} [options={}] Optional parameters\n * @param {string|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} scaled GeoJSON\n * @example\n * var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * var scaledPoly = turf.transformScale(poly, 3);\n *\n * //addToMap\n * var addToMap = [poly, scaledPoly];\n * scaledPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformScale(geojson, factor, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var origin = options.origin;\n var mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson required\");\n if (typeof factor !== \"number\" || factor <= 0)\n throw new Error(\"invalid factor\");\n var originIsPoint = Array.isArray(origin) || typeof origin === \"object\";\n\n // Clone geojson to avoid side effects\n if (mutate !== true) geojson = clone(geojson);\n\n // Scale each Feature separately\n if (geojson.type === \"FeatureCollection\" && !originIsPoint) {\n featureEach(geojson, function (feature, index) {\n geojson.features[index] = scale(feature, factor, origin);\n });\n return geojson;\n }\n // Scale Feature/Geometry\n return scale(geojson, factor, origin);\n}\n\n/**\n * Scale Feature/Geometry\n *\n * @private\n * @param {Feature|Geometry} feature GeoJSON Feature/Geometry\n * @param {number} factor of scaling, positive or negative values greater than 0\n * @param {string|Coord} [origin=\"centroid\"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @returns {Feature|Geometry} scaled GeoJSON Feature/Geometry\n */\nfunction scale(feature, factor, origin) {\n // Default params\n var isPoint = getType(feature) === \"Point\";\n origin = defineOrigin(feature, origin);\n\n // Shortcut no-scaling\n if (factor === 1 || isPoint) return feature;\n\n // Scale each coordinate\n coordEach(feature, function (coord) {\n var originalDistance = rhumbDistance(origin, coord);\n var bearing = rhumbBearing(origin, coord);\n var newDistance = originalDistance * factor;\n var newCoord = getCoords(rhumbDestination(origin, newDistance, bearing));\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n if (coord.length === 3) coord[2] *= factor;\n });\n\n delete feature.bbox;\n\n return feature;\n}\n\n/**\n * Define Origin\n *\n * @private\n * @param {GeoJSON} geojson GeoJSON\n * @param {string|Coord} origin sw/se/nw/ne/center/centroid\n * @returns {Feature<Point>} Point origin\n */\nfunction defineOrigin(geojson, origin) {\n // Default params\n if (origin === undefined || origin === null) origin = \"centroid\";\n\n // Input Coord\n if (Array.isArray(origin) || typeof origin === \"object\")\n return getCoord(origin);\n\n // Define BBox\n var bbox = geojson.bbox\n ? geojson.bbox\n : turfBBox(geojson, { recalculate: true });\n var west = bbox[0];\n var south = bbox[1];\n var east = bbox[2];\n var north = bbox[3];\n\n switch (origin) {\n case \"sw\":\n case \"southwest\":\n case \"westsouth\":\n case \"bottomleft\":\n return point([west, south]);\n case \"se\":\n case \"southeast\":\n case \"eastsouth\":\n case \"bottomright\":\n return point([east, south]);\n case \"nw\":\n case \"northwest\":\n case \"westnorth\":\n case \"topleft\":\n return point([west, north]);\n case \"ne\":\n case \"northeast\":\n case \"eastnorth\":\n case \"topright\":\n return point([east, north]);\n case \"center\":\n return center(geojson);\n case undefined:\n case null:\n case \"centroid\":\n return centroid(geojson);\n default:\n throw new Error(\"invalid origin\");\n }\n}\n\nexport { transformScale };\nexport default transformScale;\n"],"mappings":"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","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/transform-scale",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "turf transform-scale module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -30,53 +30,60 @@
|
|
|
30
30
|
"zoom-in",
|
|
31
31
|
"zoom-out"
|
|
32
32
|
],
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"type": "module",
|
|
34
|
+
"main": "dist/cjs/index.cjs",
|
|
35
|
+
"module": "dist/esm/index.js",
|
|
36
|
+
"types": "dist/esm/index.d.ts",
|
|
35
37
|
"exports": {
|
|
36
38
|
"./package.json": "./package.json",
|
|
37
39
|
".": {
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/esm/index.d.ts",
|
|
42
|
+
"default": "./dist/esm/index.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/cjs/index.d.cts",
|
|
46
|
+
"default": "./dist/cjs/index.cjs"
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
},
|
|
43
|
-
"types": "index.d.ts",
|
|
44
50
|
"sideEffects": false,
|
|
45
51
|
"files": [
|
|
46
|
-
"dist"
|
|
47
|
-
"index.d.ts"
|
|
52
|
+
"dist"
|
|
48
53
|
],
|
|
49
54
|
"scripts": {
|
|
50
|
-
"bench": "tsx bench.
|
|
51
|
-
"build": "
|
|
52
|
-
"docs": "tsx ../../scripts/generate-readmes",
|
|
53
|
-
"test": "npm-run-all test:*",
|
|
54
|
-
"test:tape": "tsx test.
|
|
55
|
-
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
55
|
+
"bench": "tsx bench.ts",
|
|
56
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
57
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
58
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
59
|
+
"test:tape": "tsx test.ts",
|
|
60
|
+
"test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
|
|
56
61
|
},
|
|
57
62
|
"devDependencies": {
|
|
58
|
-
"@turf/bbox-polygon": "^7.0.0
|
|
59
|
-
"@turf/hex-grid": "^7.0.0
|
|
60
|
-
"@turf/truncate": "^7.0.0
|
|
61
|
-
"benchmark": "
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
63
|
+
"@turf/bbox-polygon": "^7.0.0",
|
|
64
|
+
"@turf/hex-grid": "^7.0.0",
|
|
65
|
+
"@turf/truncate": "^7.0.0",
|
|
66
|
+
"@types/benchmark": "^2.1.5",
|
|
67
|
+
"@types/tape": "^4.2.32",
|
|
68
|
+
"benchmark": "^2.1.4",
|
|
69
|
+
"load-json-file": "^7.0.1",
|
|
70
|
+
"npm-run-all": "^4.1.5",
|
|
71
|
+
"tape": "^5.7.2",
|
|
72
|
+
"tsup": "^8.0.1",
|
|
73
|
+
"tsx": "^4.6.2",
|
|
74
|
+
"write-json-file": "^5.0.0"
|
|
68
75
|
},
|
|
69
76
|
"dependencies": {
|
|
70
|
-
"@turf/bbox": "^7.0.0
|
|
71
|
-
"@turf/center": "^7.0.0
|
|
72
|
-
"@turf/centroid": "^7.0.0
|
|
73
|
-
"@turf/clone": "^7.0.0
|
|
74
|
-
"@turf/helpers": "^7.0.0
|
|
75
|
-
"@turf/invariant": "^7.0.0
|
|
76
|
-
"@turf/meta": "^7.0.0
|
|
77
|
-
"@turf/rhumb-bearing": "^7.0.0
|
|
78
|
-
"@turf/rhumb-destination": "^7.0.0
|
|
79
|
-
"@turf/rhumb-distance": "^7.0.0
|
|
77
|
+
"@turf/bbox": "^7.0.0",
|
|
78
|
+
"@turf/center": "^7.0.0",
|
|
79
|
+
"@turf/centroid": "^7.0.0",
|
|
80
|
+
"@turf/clone": "^7.0.0",
|
|
81
|
+
"@turf/helpers": "^7.0.0",
|
|
82
|
+
"@turf/invariant": "^7.0.0",
|
|
83
|
+
"@turf/meta": "^7.0.0",
|
|
84
|
+
"@turf/rhumb-bearing": "^7.0.0",
|
|
85
|
+
"@turf/rhumb-destination": "^7.0.0",
|
|
86
|
+
"@turf/rhumb-distance": "^7.0.0"
|
|
80
87
|
},
|
|
81
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
|
|
82
89
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import clone from '@turf/clone';
|
|
2
|
-
import center from '@turf/center';
|
|
3
|
-
import centroid from '@turf/centroid';
|
|
4
|
-
import turfBBox from '@turf/bbox';
|
|
5
|
-
import rhumbBearing from '@turf/rhumb-bearing';
|
|
6
|
-
import rhumbDistance from '@turf/rhumb-distance';
|
|
7
|
-
import rhumbDestination from '@turf/rhumb-destination';
|
|
8
|
-
import { featureEach, coordEach } from '@turf/meta';
|
|
9
|
-
import { isObject, point } from '@turf/helpers';
|
|
10
|
-
import { getType, getCoords, getCoord } from '@turf/invariant';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger).
|
|
14
|
-
* If a FeatureCollection is provided, the origin point will be calculated based on each individual Feature.
|
|
15
|
-
*
|
|
16
|
-
* @name transformScale
|
|
17
|
-
* @param {GeoJSON} geojson GeoJSON to be scaled
|
|
18
|
-
* @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.
|
|
19
|
-
* @param {Object} [options={}] Optional parameters
|
|
20
|
-
* @param {string|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)
|
|
21
|
-
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
22
|
-
* @returns {GeoJSON} scaled GeoJSON
|
|
23
|
-
* @example
|
|
24
|
-
* var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
|
|
25
|
-
* var scaledPoly = turf.transformScale(poly, 3);
|
|
26
|
-
*
|
|
27
|
-
* //addToMap
|
|
28
|
-
* var addToMap = [poly, scaledPoly];
|
|
29
|
-
* scaledPoly.properties = {stroke: '#F00', 'stroke-width': 4};
|
|
30
|
-
*/
|
|
31
|
-
function transformScale(geojson, factor, options) {
|
|
32
|
-
// Optional parameters
|
|
33
|
-
options = options || {};
|
|
34
|
-
if (!isObject(options)) throw new Error("options is invalid");
|
|
35
|
-
var origin = options.origin;
|
|
36
|
-
var mutate = options.mutate;
|
|
37
|
-
|
|
38
|
-
// Input validation
|
|
39
|
-
if (!geojson) throw new Error("geojson required");
|
|
40
|
-
if (typeof factor !== "number" || factor <= 0)
|
|
41
|
-
throw new Error("invalid factor");
|
|
42
|
-
var originIsPoint = Array.isArray(origin) || typeof origin === "object";
|
|
43
|
-
|
|
44
|
-
// Clone geojson to avoid side effects
|
|
45
|
-
if (mutate !== true) geojson = clone(geojson);
|
|
46
|
-
|
|
47
|
-
// Scale each Feature separately
|
|
48
|
-
if (geojson.type === "FeatureCollection" && !originIsPoint) {
|
|
49
|
-
featureEach(geojson, function (feature, index) {
|
|
50
|
-
geojson.features[index] = scale(feature, factor, origin);
|
|
51
|
-
});
|
|
52
|
-
return geojson;
|
|
53
|
-
}
|
|
54
|
-
// Scale Feature/Geometry
|
|
55
|
-
return scale(geojson, factor, origin);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Scale Feature/Geometry
|
|
60
|
-
*
|
|
61
|
-
* @private
|
|
62
|
-
* @param {Feature|Geometry} feature GeoJSON Feature/Geometry
|
|
63
|
-
* @param {number} factor of scaling, positive or negative values greater than 0
|
|
64
|
-
* @param {string|Coord} [origin="centroid"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)
|
|
65
|
-
* @returns {Feature|Geometry} scaled GeoJSON Feature/Geometry
|
|
66
|
-
*/
|
|
67
|
-
function scale(feature, factor, origin) {
|
|
68
|
-
// Default params
|
|
69
|
-
var isPoint = getType(feature) === "Point";
|
|
70
|
-
origin = defineOrigin(feature, origin);
|
|
71
|
-
|
|
72
|
-
// Shortcut no-scaling
|
|
73
|
-
if (factor === 1 || isPoint) return feature;
|
|
74
|
-
|
|
75
|
-
// Scale each coordinate
|
|
76
|
-
coordEach(feature, function (coord) {
|
|
77
|
-
var originalDistance = rhumbDistance(origin, coord);
|
|
78
|
-
var bearing = rhumbBearing(origin, coord);
|
|
79
|
-
var newDistance = originalDistance * factor;
|
|
80
|
-
var newCoord = getCoords(rhumbDestination(origin, newDistance, bearing));
|
|
81
|
-
coord[0] = newCoord[0];
|
|
82
|
-
coord[1] = newCoord[1];
|
|
83
|
-
if (coord.length === 3) coord[2] *= factor;
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
delete feature.bbox;
|
|
87
|
-
|
|
88
|
-
return feature;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Define Origin
|
|
93
|
-
*
|
|
94
|
-
* @private
|
|
95
|
-
* @param {GeoJSON} geojson GeoJSON
|
|
96
|
-
* @param {string|Coord} origin sw/se/nw/ne/center/centroid
|
|
97
|
-
* @returns {Feature<Point>} Point origin
|
|
98
|
-
*/
|
|
99
|
-
function defineOrigin(geojson, origin) {
|
|
100
|
-
// Default params
|
|
101
|
-
if (origin === undefined || origin === null) origin = "centroid";
|
|
102
|
-
|
|
103
|
-
// Input Coord
|
|
104
|
-
if (Array.isArray(origin) || typeof origin === "object")
|
|
105
|
-
return getCoord(origin);
|
|
106
|
-
|
|
107
|
-
// Define BBox
|
|
108
|
-
var bbox = geojson.bbox
|
|
109
|
-
? geojson.bbox
|
|
110
|
-
: turfBBox(geojson, { recalculate: true });
|
|
111
|
-
var west = bbox[0];
|
|
112
|
-
var south = bbox[1];
|
|
113
|
-
var east = bbox[2];
|
|
114
|
-
var north = bbox[3];
|
|
115
|
-
|
|
116
|
-
switch (origin) {
|
|
117
|
-
case "sw":
|
|
118
|
-
case "southwest":
|
|
119
|
-
case "westsouth":
|
|
120
|
-
case "bottomleft":
|
|
121
|
-
return point([west, south]);
|
|
122
|
-
case "se":
|
|
123
|
-
case "southeast":
|
|
124
|
-
case "eastsouth":
|
|
125
|
-
case "bottomright":
|
|
126
|
-
return point([east, south]);
|
|
127
|
-
case "nw":
|
|
128
|
-
case "northwest":
|
|
129
|
-
case "westnorth":
|
|
130
|
-
case "topleft":
|
|
131
|
-
return point([west, north]);
|
|
132
|
-
case "ne":
|
|
133
|
-
case "northeast":
|
|
134
|
-
case "eastnorth":
|
|
135
|
-
case "topright":
|
|
136
|
-
return point([east, north]);
|
|
137
|
-
case "center":
|
|
138
|
-
return center(geojson);
|
|
139
|
-
case undefined:
|
|
140
|
-
case null:
|
|
141
|
-
case "centroid":
|
|
142
|
-
return centroid(geojson);
|
|
143
|
-
default:
|
|
144
|
-
throw new Error("invalid origin");
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export default transformScale;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var clone = require('@turf/clone');
|
|
4
|
-
var center = require('@turf/center');
|
|
5
|
-
var centroid = require('@turf/centroid');
|
|
6
|
-
var turfBBox = require('@turf/bbox');
|
|
7
|
-
var rhumbBearing = require('@turf/rhumb-bearing');
|
|
8
|
-
var rhumbDistance = require('@turf/rhumb-distance');
|
|
9
|
-
var rhumbDestination = require('@turf/rhumb-destination');
|
|
10
|
-
var meta = require('@turf/meta');
|
|
11
|
-
var helpers = require('@turf/helpers');
|
|
12
|
-
var invariant = require('@turf/invariant');
|
|
13
|
-
|
|
14
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
-
|
|
16
|
-
var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
|
|
17
|
-
var center__default = /*#__PURE__*/_interopDefaultLegacy(center);
|
|
18
|
-
var centroid__default = /*#__PURE__*/_interopDefaultLegacy(centroid);
|
|
19
|
-
var turfBBox__default = /*#__PURE__*/_interopDefaultLegacy(turfBBox);
|
|
20
|
-
var rhumbBearing__default = /*#__PURE__*/_interopDefaultLegacy(rhumbBearing);
|
|
21
|
-
var rhumbDistance__default = /*#__PURE__*/_interopDefaultLegacy(rhumbDistance);
|
|
22
|
-
var rhumbDestination__default = /*#__PURE__*/_interopDefaultLegacy(rhumbDestination);
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger).
|
|
26
|
-
* If a FeatureCollection is provided, the origin point will be calculated based on each individual Feature.
|
|
27
|
-
*
|
|
28
|
-
* @name transformScale
|
|
29
|
-
* @param {GeoJSON} geojson GeoJSON to be scaled
|
|
30
|
-
* @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.
|
|
31
|
-
* @param {Object} [options={}] Optional parameters
|
|
32
|
-
* @param {string|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)
|
|
33
|
-
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
34
|
-
* @returns {GeoJSON} scaled GeoJSON
|
|
35
|
-
* @example
|
|
36
|
-
* var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
|
|
37
|
-
* var scaledPoly = turf.transformScale(poly, 3);
|
|
38
|
-
*
|
|
39
|
-
* //addToMap
|
|
40
|
-
* var addToMap = [poly, scaledPoly];
|
|
41
|
-
* scaledPoly.properties = {stroke: '#F00', 'stroke-width': 4};
|
|
42
|
-
*/
|
|
43
|
-
function transformScale(geojson, factor, options) {
|
|
44
|
-
// Optional parameters
|
|
45
|
-
options = options || {};
|
|
46
|
-
if (!helpers.isObject(options)) throw new Error("options is invalid");
|
|
47
|
-
var origin = options.origin;
|
|
48
|
-
var mutate = options.mutate;
|
|
49
|
-
|
|
50
|
-
// Input validation
|
|
51
|
-
if (!geojson) throw new Error("geojson required");
|
|
52
|
-
if (typeof factor !== "number" || factor <= 0)
|
|
53
|
-
throw new Error("invalid factor");
|
|
54
|
-
var originIsPoint = Array.isArray(origin) || typeof origin === "object";
|
|
55
|
-
|
|
56
|
-
// Clone geojson to avoid side effects
|
|
57
|
-
if (mutate !== true) geojson = clone__default['default'](geojson);
|
|
58
|
-
|
|
59
|
-
// Scale each Feature separately
|
|
60
|
-
if (geojson.type === "FeatureCollection" && !originIsPoint) {
|
|
61
|
-
meta.featureEach(geojson, function (feature, index) {
|
|
62
|
-
geojson.features[index] = scale(feature, factor, origin);
|
|
63
|
-
});
|
|
64
|
-
return geojson;
|
|
65
|
-
}
|
|
66
|
-
// Scale Feature/Geometry
|
|
67
|
-
return scale(geojson, factor, origin);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Scale Feature/Geometry
|
|
72
|
-
*
|
|
73
|
-
* @private
|
|
74
|
-
* @param {Feature|Geometry} feature GeoJSON Feature/Geometry
|
|
75
|
-
* @param {number} factor of scaling, positive or negative values greater than 0
|
|
76
|
-
* @param {string|Coord} [origin="centroid"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)
|
|
77
|
-
* @returns {Feature|Geometry} scaled GeoJSON Feature/Geometry
|
|
78
|
-
*/
|
|
79
|
-
function scale(feature, factor, origin) {
|
|
80
|
-
// Default params
|
|
81
|
-
var isPoint = invariant.getType(feature) === "Point";
|
|
82
|
-
origin = defineOrigin(feature, origin);
|
|
83
|
-
|
|
84
|
-
// Shortcut no-scaling
|
|
85
|
-
if (factor === 1 || isPoint) return feature;
|
|
86
|
-
|
|
87
|
-
// Scale each coordinate
|
|
88
|
-
meta.coordEach(feature, function (coord) {
|
|
89
|
-
var originalDistance = rhumbDistance__default['default'](origin, coord);
|
|
90
|
-
var bearing = rhumbBearing__default['default'](origin, coord);
|
|
91
|
-
var newDistance = originalDistance * factor;
|
|
92
|
-
var newCoord = invariant.getCoords(rhumbDestination__default['default'](origin, newDistance, bearing));
|
|
93
|
-
coord[0] = newCoord[0];
|
|
94
|
-
coord[1] = newCoord[1];
|
|
95
|
-
if (coord.length === 3) coord[2] *= factor;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
delete feature.bbox;
|
|
99
|
-
|
|
100
|
-
return feature;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Define Origin
|
|
105
|
-
*
|
|
106
|
-
* @private
|
|
107
|
-
* @param {GeoJSON} geojson GeoJSON
|
|
108
|
-
* @param {string|Coord} origin sw/se/nw/ne/center/centroid
|
|
109
|
-
* @returns {Feature<Point>} Point origin
|
|
110
|
-
*/
|
|
111
|
-
function defineOrigin(geojson, origin) {
|
|
112
|
-
// Default params
|
|
113
|
-
if (origin === undefined || origin === null) origin = "centroid";
|
|
114
|
-
|
|
115
|
-
// Input Coord
|
|
116
|
-
if (Array.isArray(origin) || typeof origin === "object")
|
|
117
|
-
return invariant.getCoord(origin);
|
|
118
|
-
|
|
119
|
-
// Define BBox
|
|
120
|
-
var bbox = geojson.bbox
|
|
121
|
-
? geojson.bbox
|
|
122
|
-
: turfBBox__default['default'](geojson, { recalculate: true });
|
|
123
|
-
var west = bbox[0];
|
|
124
|
-
var south = bbox[1];
|
|
125
|
-
var east = bbox[2];
|
|
126
|
-
var north = bbox[3];
|
|
127
|
-
|
|
128
|
-
switch (origin) {
|
|
129
|
-
case "sw":
|
|
130
|
-
case "southwest":
|
|
131
|
-
case "westsouth":
|
|
132
|
-
case "bottomleft":
|
|
133
|
-
return helpers.point([west, south]);
|
|
134
|
-
case "se":
|
|
135
|
-
case "southeast":
|
|
136
|
-
case "eastsouth":
|
|
137
|
-
case "bottomright":
|
|
138
|
-
return helpers.point([east, south]);
|
|
139
|
-
case "nw":
|
|
140
|
-
case "northwest":
|
|
141
|
-
case "westnorth":
|
|
142
|
-
case "topleft":
|
|
143
|
-
return helpers.point([west, north]);
|
|
144
|
-
case "ne":
|
|
145
|
-
case "northeast":
|
|
146
|
-
case "eastnorth":
|
|
147
|
-
case "topright":
|
|
148
|
-
return helpers.point([east, north]);
|
|
149
|
-
case "center":
|
|
150
|
-
return center__default['default'](geojson);
|
|
151
|
-
case undefined:
|
|
152
|
-
case null:
|
|
153
|
-
case "centroid":
|
|
154
|
-
return centroid__default['default'](geojson);
|
|
155
|
-
default:
|
|
156
|
-
throw new Error("invalid origin");
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
module.exports = transformScale;
|
|
161
|
-
module.exports.default = transformScale;
|
package/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Corners, Coord, AllGeoJSON } from "@turf/helpers";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* http://turfjs.org/docs/#transformscale
|
|
5
|
-
*/
|
|
6
|
-
export default function transformScale<T extends AllGeoJSON>(
|
|
7
|
-
geojson: T,
|
|
8
|
-
factor: number,
|
|
9
|
-
options?: {
|
|
10
|
-
origin?: Corners | Coord;
|
|
11
|
-
mutate?: boolean;
|
|
12
|
-
}
|
|
13
|
-
): T;
|