@turf/projection
Advanced tools
Comparing version 4.7.3 to 5.0.4
@@ -1,9 +0,12 @@ | ||
/// <reference types="geojson" /> | ||
import { AllGeoJSON, Position} from '@turf/helpers'; | ||
type Types = GeoJSON.FeatureCollection<any> | GeoJSON.Feature<any> | GeoJSON.GeometryObject | GeoJSON.GeometryCollection; | ||
/** | ||
* http://turfjs.org/docs/#toMercator | ||
*/ | ||
export function toMercator<T extends Types>(geojson: T, mutate?: boolean): T; | ||
export function toMercator<T extends AllGeoJSON | Position>( | ||
geojson: T, | ||
options?: { | ||
mutate?: boolean | ||
} | ||
): T; | ||
@@ -13,2 +16,7 @@ /** | ||
*/ | ||
export function toWgs84<T extends Types>(geojson: T, mutate?: boolean): T; | ||
export function toWgs84<T extends AllGeoJSON | Position>( | ||
geojson: T, | ||
options?: { | ||
mutate?: boolean | ||
} | ||
): T; |
61
index.js
@@ -1,9 +0,5 @@ | ||
var coordEach = require('@turf/meta').coordEach; | ||
var clone = require('@turf/clone'); | ||
import { coordEach } from '@turf/meta'; | ||
import { isObject, isNumber } from '@turf/helpers'; | ||
import clone from '@turf/clone'; | ||
module.exports = { | ||
toMercator: toMercator, | ||
toWgs84: toWgs84 | ||
}; | ||
/** | ||
@@ -13,4 +9,5 @@ * Converts a WGS84 GeoJSON object into Mercator (EPSG:900913) projection | ||
* @name toMercator | ||
* @param {GeoJSON} geojson WGS84 GeoJSON object | ||
* @param {boolean} [mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @param {GeoJSON|Position} geojson WGS84 GeoJSON object | ||
* @param {Object} [options] Optional parameters | ||
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @returns {GeoJSON} true/false | ||
@@ -24,4 +21,4 @@ * @example | ||
*/ | ||
function toMercator(geojson, mutate) { | ||
return convert(geojson, mutate, 'mercator'); | ||
export function toMercator(geojson, options) { | ||
return convert(geojson, 'mercator', options); | ||
} | ||
@@ -33,4 +30,5 @@ | ||
* @name toWgs84 | ||
* @param {GeoJSON} geojson Mercator GeoJSON object | ||
* @param {boolean} [mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @param {GeoJSON|Position} geojson Mercator GeoJSON object | ||
* @param {Object} [options] Optional parameters | ||
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @returns {GeoJSON} true/false | ||
@@ -44,4 +42,4 @@ * @example | ||
*/ | ||
function toWgs84(geojson, mutate) { | ||
return convert(geojson, mutate, 'wgs84'); | ||
export function toWgs84(geojson, options) { | ||
return convert(geojson, 'wgs84', options); | ||
} | ||
@@ -55,17 +53,30 @@ | ||
* @param {GeoJSON} geojson GeoJSON Feature or Geometry | ||
* @param {boolean} [mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @param {string} projection defines the projection system to convert the coordinates to | ||
* @param {Object} [options] Optional parameters | ||
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @returns {GeoJSON} true/false | ||
*/ | ||
function convert(geojson, mutate, projection) { | ||
function convert(geojson, projection, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var mutate = options.mutate; | ||
// Validation | ||
if (!geojson) throw new Error('geojson is required'); | ||
if (mutate !== true) geojson = clone(geojson); | ||
// Handle Position | ||
if (Array.isArray(geojson) && isNumber(geojson[0])) geojson = (projection === 'mercator') ? convertToMercator(geojson) : convertToWgs84(geojson); | ||
coordEach(geojson, function (coord) { | ||
var newCoord = (projection === 'mercator') ? convertToMercator(coord) : convertToWgs84(coord); | ||
coord[0] = newCoord[0]; | ||
coord[1] = newCoord[1]; | ||
}); | ||
// Handle GeoJSON | ||
else { | ||
// Handle possible data mutation | ||
if (mutate !== true) geojson = clone(geojson); | ||
coordEach(geojson, function (coord) { | ||
var newCoord = (projection === 'mercator') ? convertToMercator(coord) : convertToWgs84(coord); | ||
coord[0] = newCoord[0]; | ||
coord[1] = newCoord[1]; | ||
}); | ||
} | ||
return geojson; | ||
@@ -115,4 +126,4 @@ } | ||
// 900913 properties. | ||
var R2D = 180 / Math.PI, | ||
A = 6378137.0; | ||
var R2D = 180 / Math.PI; | ||
var A = 6378137.0; | ||
@@ -119,0 +130,0 @@ return [ |
{ | ||
"name": "@turf/projection", | ||
"version": "4.7.3", | ||
"version": "5.0.4", | ||
"description": "turf projection module", | ||
"main": "index.js", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"main.js" | ||
], | ||
"scripts": { | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"bench": "node -r @std/esm bench.js" | ||
}, | ||
@@ -44,14 +48,20 @@ "repository": { | ||
"devDependencies": { | ||
"@turf/helpers": "^4.7.3", | ||
"@turf/truncate": "^4.7.3", | ||
"benchmark": "^2.1.4", | ||
"load-json-file": "^2.0.0", | ||
"proj4": "2.4.4", | ||
"tape": "^4.6.3", | ||
"write-json-file": "^2.2.0" | ||
"@std/esm": "*", | ||
"@turf/truncate": "^5.0.4", | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"proj4": "*", | ||
"rollup": "*", | ||
"tape": "*", | ||
"write-json-file": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/clone": "^4.7.3", | ||
"@turf/meta": "^4.7.3" | ||
"@turf/clone": "^5.0.4", | ||
"@turf/helpers": "^5.0.4", | ||
"@turf/meta": "^5.0.4" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/projection | ||
# toMercator | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## toMercator | ||
Converts a WGS84 GeoJSON object into Mercator (EPSG:900913) projection | ||
@@ -9,4 +11,5 @@ | ||
- `geojson` **[GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects)** WGS84 GeoJSON object | ||
- `mutate` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
- `geojson` **([GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects) | Position)** WGS84 GeoJSON object | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Optional parameters | ||
- `options.mutate` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
@@ -25,3 +28,3 @@ **Examples** | ||
# toWgs84 | ||
## toWgs84 | ||
@@ -32,4 +35,5 @@ Converts a Mercator (EPSG:900913) GeoJSON object into WGS84 projection | ||
- `geojson` **[GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects)** Mercator GeoJSON object | ||
- `mutate` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
- `geojson` **([GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects) | Position)** Mercator GeoJSON object | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Optional parameters | ||
- `options.mutate` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
@@ -36,0 +40,0 @@ **Examples** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14116
6
272
73
3
8
1
+ Added@turf/helpers@^5.0.4
+ Added@turf/clone@5.1.5(transitive)
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/meta@5.2.0(transitive)
- Removed@turf/clone@4.7.3(transitive)
- Removed@turf/meta@4.7.4(transitive)
Updated@turf/clone@^5.0.4
Updated@turf/meta@^5.0.4