@turf/projection
Advanced tools
+6
-12
@@ -14,9 +14,7 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts | ||
| var mutate = options.mutate; | ||
| if (!geojson) | ||
| throw new Error("geojson is required"); | ||
| if (!geojson) throw new Error("geojson is required"); | ||
| if (Array.isArray(geojson) && _helpers.isNumber.call(void 0, geojson[0])) | ||
| geojson = projection === "mercator" ? convertToMercator(geojson) : convertToWgs84(geojson); | ||
| else { | ||
| if (mutate !== true) | ||
| geojson = _clone.clone.call(void 0, geojson); | ||
| if (mutate !== true) geojson = _clone.clone.call(void 0, geojson); | ||
| _meta.coordEach.call(void 0, geojson, function(coord) { | ||
@@ -37,10 +35,6 @@ var newCoord = projection === "mercator" ? convertToMercator(coord) : convertToWgs84(coord); | ||
| ]; | ||
| if (xy[0] > MAXEXTENT) | ||
| xy[0] = MAXEXTENT; | ||
| if (xy[0] < -MAXEXTENT) | ||
| xy[0] = -MAXEXTENT; | ||
| if (xy[1] > MAXEXTENT) | ||
| xy[1] = MAXEXTENT; | ||
| if (xy[1] < -MAXEXTENT) | ||
| xy[1] = -MAXEXTENT; | ||
| if (xy[0] > MAXEXTENT) xy[0] = MAXEXTENT; | ||
| if (xy[0] < -MAXEXTENT) xy[0] = -MAXEXTENT; | ||
| if (xy[1] > MAXEXTENT) xy[1] = MAXEXTENT; | ||
| if (xy[1] < -MAXEXTENT) xy[1] = -MAXEXTENT; | ||
| return xy; | ||
@@ -47,0 +41,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAqB,gBAAgB;AACrC,SAAS,aAAa;AAiBtB,SAAS,WACP,SACA,UAAgC,CAAC,GAC9B;AACH,SAAO,QAAQ,SAAS,YAAY,OAAO;AAC7C;AAiBA,SAAS,QACP,SACA,UAAgC,CAAC,GAC9B;AACH,SAAO,QAAQ,SAAS,SAAS,OAAO;AAC1C;AAYA,SAAS,QACP,SACA,Y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AC,IAAI,MAAO;AAAA,KACf,KAAK,KAAK,MAAM,IAAM,KAAK,KAAK,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK;AAAA,EAC5D;AACF;AASA,SAAS,KAAK,GAAW;AACvB,SAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC","sourcesContent":["import { Position } from \"geojson\";\nimport { coordEach } from \"@turf/meta\";\nimport { AllGeoJSON, isNumber } from \"@turf/helpers\";\nimport { clone } from \"@turf/clone\";\n\n/**\n * Converts a WGS84 GeoJSON object into Mercator (EPSG:900913) projection\n *\n * @name toMercator\n * @param {GeoJSON|Position} geojson WGS84 GeoJSON object\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Projected GeoJSON\n * @example\n * var pt = turf.point([-71,41]);\n * var converted = turf.toMercator(pt);\n *\n * //addToMap\n * var addToMap = [pt, converted];\n */\nfunction toMercator<G = AllGeoJSON | Position>(\n geojson: G,\n options: { mutate?: boolean } = {}\n): G {\n return convert(geojson, \"mercator\", options);\n}\n\n/**\n * Converts a Mercator (EPSG:900913) GeoJSON object into WGS84 projection\n *\n * @name toWgs84\n * @param {GeoJSON|Position} geojson Mercator GeoJSON object\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Projected GeoJSON\n * @example\n * var pt = turf.point([-7903683.846322424, 5012341.663847514]);\n * var converted = turf.toWgs84(pt);\n *\n * //addToMap\n * var addToMap = [pt, converted];\n */\nfunction toWgs84<G = AllGeoJSON | Position>(\n geojson: G,\n options: { mutate?: boolean } = {}\n): G {\n return convert(geojson, \"wgs84\", options);\n}\n\n/**\n * Converts a GeoJSON coordinates to the defined `projection`\n *\n * @private\n * @param {GeoJSON} geojson GeoJSON Feature or Geometry\n * @param {string} projection defines the projection system to convert the coordinates to\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Converted GeoJSON\n */\nfunction convert(\n geojson: any,\n projection: string,\n options: { mutate?: boolean } = {}\n): any {\n // Optional parameters\n options = options || {};\n var mutate = options.mutate;\n\n // Validation\n if (!geojson) throw new Error(\"geojson is required\");\n\n // Handle Position\n if (Array.isArray(geojson) && isNumber(geojson[0]))\n geojson =\n projection === \"mercator\"\n ? convertToMercator(geojson)\n : convertToWgs84(geojson);\n // Handle GeoJSON\n else {\n // Handle possible data mutation\n if (mutate !== true) geojson = clone(geojson);\n\n coordEach(geojson, function (coord) {\n var newCoord =\n projection === \"mercator\"\n ? convertToMercator(coord)\n : convertToWgs84(coord);\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n });\n }\n return geojson;\n}\n\n/**\n * Convert lon/lat values to 900913 x/y.\n * (from https://github.com/mapbox/sphericalmercator)\n *\n * @private\n * @param {Array<number>} lonLat WGS84 point\n * @returns {Array<number>} Mercator [x, y] point\n */\nfunction convertToMercator(lonLat: number[]) {\n var D2R = Math.PI / 180,\n // 900913 properties\n A = 6378137.0,\n MAXEXTENT = 20037508.342789244;\n\n // compensate longitudes passing the 180th meridian\n // from https://github.com/proj4js/proj4js/blob/master/lib/common/adjust_lon.js\n var adjusted =\n Math.abs(lonLat[0]) <= 180 ? lonLat[0] : lonLat[0] - sign(lonLat[0]) * 360;\n var xy = [\n A * adjusted * D2R,\n A * Math.log(Math.tan(Math.PI * 0.25 + 0.5 * lonLat[1] * D2R)),\n ];\n\n // if xy value is beyond maxextent (e.g. poles), return maxextent\n if (xy[0] > MAXEXTENT) xy[0] = MAXEXTENT;\n if (xy[0] < -MAXEXTENT) xy[0] = -MAXEXTENT;\n if (xy[1] > MAXEXTENT) xy[1] = MAXEXTENT;\n if (xy[1] < -MAXEXTENT) xy[1] = -MAXEXTENT;\n\n return xy;\n}\n\n/**\n * Convert 900913 x/y values to lon/lat.\n * (from https://github.com/mapbox/sphericalmercator)\n *\n * @private\n * @param {Array<number>} xy Mercator [x, y] point\n * @returns {Array<number>} WGS84 [lon, lat] point\n */\nfunction convertToWgs84(xy: number[]) {\n // 900913 properties.\n var R2D = 180 / Math.PI;\n var A = 6378137.0;\n\n return [\n (xy[0] * R2D) / A,\n (Math.PI * 0.5 - 2.0 * Math.atan(Math.exp(-xy[1] / A))) * R2D,\n ];\n}\n\n/**\n * Returns the sign of the input, or zero\n *\n * @private\n * @param {number} x input\n * @returns {number} -1|0|1 output\n */\nfunction sign(x: number) {\n return x < 0 ? -1 : x > 0 ? 1 : 0;\n}\n\nexport { toMercator, toWgs84 };\n"]} | ||
| {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-projection/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACCA,kCAA0B;AAC1B,wCAAqC;AACrC,oCAAsB;AAiBtB,SAAS,UAAA,CACP,OAAA,EACA,QAAA,EAAgC,CAAC,CAAA,EAC9B;AACH,EAAA,OAAO,OAAA,CAAQ,OAAA,EAAS,UAAA,EAAY,OAAO,CAAA;AAC7C;AAiBA,SAAS,OAAA,CACP,OAAA,EACA,QAAA,EAAgC,CAAC,CAAA,EAC9B;AACH,EAAA,OAAO,OAAA,CAAQ,OAAA,EAAS,OAAA,EAAS,OAAO,CAAA;AAC1C;AAYA,SAAS,OAAA,CACP,OAAA,EACA,UAAA,EACA,QAAA,EAAgC,CAAC,CAAA,EAC5B;AAEL,EAAA,QAAA,EAAU,QAAA,GAAW,CAAC,CAAA;AACtB,EAAA,IAAI,OAAA,EAAS,OAAA,CAAQ,MAAA;AAGrB,EAAA,GAAA,CAAI,CAAC,OAAA,EAAS,MAAM,IAAI,KAAA,CAAM,qBAAqB,CAAA;AAGnD,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,CAAQ,OAAO,EAAA,GAAK,+BAAA,OAAS,CAAQ,CAAC,CAAC,CAAA;AAC/C,IAAA,QAAA,EACE,WAAA,IAAe,WAAA,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,SAAA;AAC/B,EAAA,GAAA,CAAI,EAAA,CAAG,CAAC,EAAA,EAAI,CAAC,SAAA,EAAW,EAAA,CAAG,CAAC,EAAA,EAAI,CAAC,SAAA;AACjC,EAAA,GAAA,CAAI,EAAA,CAAG,CAAC,EAAA,EAAI,SAAA,EAAW,EAAA,CAAG,CAAC,EAAA,EAAI,SAAA;AAC/B,EAAA,GAAA,CAAI,EAAA,CAAG,CAAC,EAAA,EAAI,CAAC,SAAA,EAAW,EAAA,CAAG,CAAC,EAAA,EAAI,CAAC,SAAA;AAEjC,EAAA,OAAO,EAAA;AACT;AAUA,SAAS,cAAA,CAAe,EAAA,EAAc;AAEpC,EAAA,IAAI,IAAA,EAAM,IAAA,EAAM,IAAA,CAAK,EAAA;AACrB,EAAA,IAAI,EAAA,EAAI,OAAA;AAER,EAAA,OAAO;AAAA,IACJ,EAAA,CAAG,CAAC,EAAA,EAAI,IAAA,EAAO,CAAA;AAAA,IAAA,CACf,IAAA,CAAK,GAAA,EAAK,IAAA,EAAM,EAAA,EAAM,IAAA,CAAK,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,CAAC,EAAA,CAAG,CAAC,EAAA,EAAI,CAAC,CAAC,CAAA,EAAA,EAAK;AAAA,EAC5D,CAAA;AACF;AASA,SAAS,IAAA,CAAK,CAAA,EAAW;AACvB,EAAA,OAAO,EAAA,EAAI,EAAA,EAAI,CAAA,EAAA,EAAK,EAAA,EAAI,EAAA,EAAI,EAAA,EAAI,CAAA;AAClC;ADxGA;AACE;AACA;AACF,2DAAC","file":"/home/runner/work/turf/turf/packages/turf-projection/dist/cjs/index.cjs","sourcesContent":[null,"import { Position } from \"geojson\";\nimport { coordEach } from \"@turf/meta\";\nimport { AllGeoJSON, isNumber } from \"@turf/helpers\";\nimport { clone } from \"@turf/clone\";\n\n/**\n * Converts a WGS84 GeoJSON object into Mercator (EPSG:900913) projection\n *\n * @function\n * @param {GeoJSON|Position} geojson WGS84 GeoJSON object\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Projected GeoJSON\n * @example\n * var pt = turf.point([-71,41]);\n * var converted = turf.toMercator(pt);\n *\n * //addToMap\n * var addToMap = [pt, converted];\n */\nfunction toMercator<G = AllGeoJSON | Position>(\n geojson: G,\n options: { mutate?: boolean } = {}\n): G {\n return convert(geojson, \"mercator\", options);\n}\n\n/**\n * Converts a Mercator (EPSG:900913) GeoJSON object into WGS84 projection\n *\n * @function\n * @param {GeoJSON|Position} geojson Mercator GeoJSON object\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Projected GeoJSON\n * @example\n * var pt = turf.point([-7903683.846322424, 5012341.663847514]);\n * var converted = turf.toWgs84(pt);\n *\n * //addToMap\n * var addToMap = [pt, converted];\n */\nfunction toWgs84<G = AllGeoJSON | Position>(\n geojson: G,\n options: { mutate?: boolean } = {}\n): G {\n return convert(geojson, \"wgs84\", options);\n}\n\n/**\n * Converts a GeoJSON coordinates to the defined `projection`\n *\n * @private\n * @param {GeoJSON} geojson GeoJSON Feature or Geometry\n * @param {string} projection defines the projection system to convert the coordinates to\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Converted GeoJSON\n */\nfunction convert(\n geojson: any,\n projection: string,\n options: { mutate?: boolean } = {}\n): any {\n // Optional parameters\n options = options || {};\n var mutate = options.mutate;\n\n // Validation\n if (!geojson) throw new Error(\"geojson is required\");\n\n // Handle Position\n if (Array.isArray(geojson) && isNumber(geojson[0]))\n geojson =\n projection === \"mercator\"\n ? convertToMercator(geojson)\n : convertToWgs84(geojson);\n // Handle GeoJSON\n else {\n // Handle possible data mutation\n if (mutate !== true) geojson = clone(geojson);\n\n coordEach(geojson, function (coord) {\n var newCoord =\n projection === \"mercator\"\n ? convertToMercator(coord)\n : convertToWgs84(coord);\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n });\n }\n return geojson;\n}\n\n/**\n * Convert lon/lat values to 900913 x/y.\n * (from https://github.com/mapbox/sphericalmercator)\n *\n * @private\n * @param {Array<number>} lonLat WGS84 point\n * @returns {Array<number>} Mercator [x, y] point\n */\nfunction convertToMercator(lonLat: number[]) {\n var D2R = Math.PI / 180,\n // 900913 properties\n A = 6378137.0,\n MAXEXTENT = 20037508.342789244;\n\n // compensate longitudes passing the 180th meridian\n // from https://github.com/proj4js/proj4js/blob/master/lib/common/adjust_lon.js\n var adjusted =\n Math.abs(lonLat[0]) <= 180 ? lonLat[0] : lonLat[0] - sign(lonLat[0]) * 360;\n var xy = [\n A * adjusted * D2R,\n A * Math.log(Math.tan(Math.PI * 0.25 + 0.5 * lonLat[1] * D2R)),\n ];\n\n // if xy value is beyond maxextent (e.g. poles), return maxextent\n if (xy[0] > MAXEXTENT) xy[0] = MAXEXTENT;\n if (xy[0] < -MAXEXTENT) xy[0] = -MAXEXTENT;\n if (xy[1] > MAXEXTENT) xy[1] = MAXEXTENT;\n if (xy[1] < -MAXEXTENT) xy[1] = -MAXEXTENT;\n\n return xy;\n}\n\n/**\n * Convert 900913 x/y values to lon/lat.\n * (from https://github.com/mapbox/sphericalmercator)\n *\n * @private\n * @param {Array<number>} xy Mercator [x, y] point\n * @returns {Array<number>} WGS84 [lon, lat] point\n */\nfunction convertToWgs84(xy: number[]) {\n // 900913 properties.\n var R2D = 180 / Math.PI;\n var A = 6378137.0;\n\n return [\n (xy[0] * R2D) / A,\n (Math.PI * 0.5 - 2.0 * Math.atan(Math.exp(-xy[1] / A))) * R2D,\n ];\n}\n\n/**\n * Returns the sign of the input, or zero\n *\n * @private\n * @param {number} x input\n * @returns {number} -1|0|1 output\n */\nfunction sign(x: number) {\n return x < 0 ? -1 : x > 0 ? 1 : 0;\n}\n\nexport { toMercator, toWgs84 };\n"]} |
@@ -7,3 +7,3 @@ import { Position } from 'geojson'; | ||
| * | ||
| * @name toMercator | ||
| * @function | ||
| * @param {GeoJSON|Position} geojson WGS84 GeoJSON object | ||
@@ -26,3 +26,3 @@ * @param {Object} [options] Optional parameters | ||
| * | ||
| * @name toWgs84 | ||
| * @function | ||
| * @param {GeoJSON|Position} geojson Mercator GeoJSON object | ||
@@ -29,0 +29,0 @@ * @param {Object} [options] Optional parameters |
@@ -7,3 +7,3 @@ import { Position } from 'geojson'; | ||
| * | ||
| * @name toMercator | ||
| * @function | ||
| * @param {GeoJSON|Position} geojson WGS84 GeoJSON object | ||
@@ -26,3 +26,3 @@ * @param {Object} [options] Optional parameters | ||
| * | ||
| * @name toWgs84 | ||
| * @function | ||
| * @param {GeoJSON|Position} geojson Mercator GeoJSON object | ||
@@ -29,0 +29,0 @@ * @param {Object} [options] Optional parameters |
+6
-12
@@ -14,9 +14,7 @@ // index.ts | ||
| var mutate = options.mutate; | ||
| if (!geojson) | ||
| throw new Error("geojson is required"); | ||
| if (!geojson) throw new Error("geojson is required"); | ||
| if (Array.isArray(geojson) && isNumber(geojson[0])) | ||
| geojson = projection === "mercator" ? convertToMercator(geojson) : convertToWgs84(geojson); | ||
| else { | ||
| if (mutate !== true) | ||
| geojson = clone(geojson); | ||
| if (mutate !== true) geojson = clone(geojson); | ||
| coordEach(geojson, function(coord) { | ||
@@ -37,10 +35,6 @@ var newCoord = projection === "mercator" ? convertToMercator(coord) : convertToWgs84(coord); | ||
| ]; | ||
| if (xy[0] > MAXEXTENT) | ||
| xy[0] = MAXEXTENT; | ||
| if (xy[0] < -MAXEXTENT) | ||
| xy[0] = -MAXEXTENT; | ||
| if (xy[1] > MAXEXTENT) | ||
| xy[1] = MAXEXTENT; | ||
| if (xy[1] < -MAXEXTENT) | ||
| xy[1] = -MAXEXTENT; | ||
| if (xy[0] > MAXEXTENT) xy[0] = MAXEXTENT; | ||
| if (xy[0] < -MAXEXTENT) xy[0] = -MAXEXTENT; | ||
| if (xy[1] > MAXEXTENT) xy[1] = MAXEXTENT; | ||
| if (xy[1] < -MAXEXTENT) xy[1] = -MAXEXTENT; | ||
| return xy; | ||
@@ -47,0 +41,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Position } from \"geojson\";\nimport { coordEach } from \"@turf/meta\";\nimport { AllGeoJSON, isNumber } from \"@turf/helpers\";\nimport { clone } from \"@turf/clone\";\n\n/**\n * Converts a WGS84 GeoJSON object into Mercator (EPSG:900913) projection\n *\n * @name toMercator\n * @param {GeoJSON|Position} geojson WGS84 GeoJSON object\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Projected GeoJSON\n * @example\n * var pt = turf.point([-71,41]);\n * var converted = turf.toMercator(pt);\n *\n * //addToMap\n * var addToMap = [pt, converted];\n */\nfunction toMercator<G = AllGeoJSON | Position>(\n geojson: G,\n options: { mutate?: boolean } = {}\n): G {\n return convert(geojson, \"mercator\", options);\n}\n\n/**\n * Converts a Mercator (EPSG:900913) GeoJSON object into WGS84 projection\n *\n * @name toWgs84\n * @param {GeoJSON|Position} geojson Mercator GeoJSON object\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Projected GeoJSON\n * @example\n * var pt = turf.point([-7903683.846322424, 5012341.663847514]);\n * var converted = turf.toWgs84(pt);\n *\n * //addToMap\n * var addToMap = [pt, converted];\n */\nfunction toWgs84<G = AllGeoJSON | Position>(\n geojson: G,\n options: { mutate?: boolean } = {}\n): G {\n return convert(geojson, \"wgs84\", options);\n}\n\n/**\n * Converts a GeoJSON coordinates to the defined `projection`\n *\n * @private\n * @param {GeoJSON} geojson GeoJSON Feature or Geometry\n * @param {string} projection defines the projection system to convert the coordinates to\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Converted GeoJSON\n */\nfunction convert(\n geojson: any,\n projection: string,\n options: { mutate?: boolean } = {}\n): any {\n // Optional parameters\n options = options || {};\n var mutate = options.mutate;\n\n // Validation\n if (!geojson) throw new Error(\"geojson is required\");\n\n // Handle Position\n if (Array.isArray(geojson) && isNumber(geojson[0]))\n geojson =\n projection === \"mercator\"\n ? convertToMercator(geojson)\n : convertToWgs84(geojson);\n // Handle GeoJSON\n else {\n // Handle possible data mutation\n if (mutate !== true) geojson = clone(geojson);\n\n coordEach(geojson, function (coord) {\n var newCoord =\n projection === \"mercator\"\n ? convertToMercator(coord)\n : convertToWgs84(coord);\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n });\n }\n return geojson;\n}\n\n/**\n * Convert lon/lat values to 900913 x/y.\n * (from https://github.com/mapbox/sphericalmercator)\n *\n * @private\n * @param {Array<number>} lonLat WGS84 point\n * @returns {Array<number>} Mercator [x, y] point\n */\nfunction convertToMercator(lonLat: number[]) {\n var D2R = Math.PI / 180,\n // 900913 properties\n A = 6378137.0,\n MAXEXTENT = 20037508.342789244;\n\n // compensate longitudes passing the 180th meridian\n // from https://github.com/proj4js/proj4js/blob/master/lib/common/adjust_lon.js\n var adjusted =\n Math.abs(lonLat[0]) <= 180 ? lonLat[0] : lonLat[0] - sign(lonLat[0]) * 360;\n var xy = [\n A * adjusted * D2R,\n A * Math.log(Math.tan(Math.PI * 0.25 + 0.5 * lonLat[1] * D2R)),\n ];\n\n // if xy value is beyond maxextent (e.g. poles), return maxextent\n if (xy[0] > MAXEXTENT) xy[0] = MAXEXTENT;\n if (xy[0] < -MAXEXTENT) xy[0] = -MAXEXTENT;\n if (xy[1] > MAXEXTENT) xy[1] = MAXEXTENT;\n if (xy[1] < -MAXEXTENT) xy[1] = -MAXEXTENT;\n\n return xy;\n}\n\n/**\n * Convert 900913 x/y values to lon/lat.\n * (from https://github.com/mapbox/sphericalmercator)\n *\n * @private\n * @param {Array<number>} xy Mercator [x, y] point\n * @returns {Array<number>} WGS84 [lon, lat] point\n */\nfunction convertToWgs84(xy: number[]) {\n // 900913 properties.\n var R2D = 180 / Math.PI;\n var A = 6378137.0;\n\n return [\n (xy[0] * R2D) / A,\n (Math.PI * 0.5 - 2.0 * Math.atan(Math.exp(-xy[1] / A))) * R2D,\n ];\n}\n\n/**\n * Returns the sign of the input, or zero\n *\n * @private\n * @param {number} x input\n * @returns {number} -1|0|1 output\n */\nfunction sign(x: number) {\n return x < 0 ? -1 : x > 0 ? 1 : 0;\n}\n\nexport { toMercator, toWgs84 };\n"],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAqB,gBAAgB;AACrC,SAAS,aAAa;AAiBtB,SAAS,WACP,SACA,UAAgC,CAAC,GAC9B;AACH,SAAO,QAAQ,SAAS,YAAY,OAAO;AAC7C;AAiBA,SAAS,QACP,SACA,UAAgC,CAAC,GAC9B;AACH,SAAO,QAAQ,SAAS,SAAS,OAAO;AAC1C;AAYA,SAAS,QACP,SACA,YACA,UAAgC,CAAC,GAC5B;AAEL,YAAU,WAAW,CAAC;AACtB,MAAI,SAAS,QAAQ;AAGrB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AAGnD,MAAI,MAAM,QAAQ,OAAO,KAAK,SAAS,QAAQ,CAAC,CAAC;AAC/C,cACE,eAAe,aACX,kBAAkB,OAAO,IACzB,eAAe,OAAO;AAAA,OAEzB;AAEH,QAAI,WAAW;AAAM,gBAAU,MAAM,OAAO;AAE5C,cAAU,SAAS,SAAU,OAAO;AAClC,UAAI,WACF,eAAe,aACX,kBAAkB,KAAK,IACvB,eAAe,KAAK;AAC1B,YAAM,CAAC,IAAI,SAAS,CAAC;AACrB,YAAM,CAAC,IAAI,SAAS,CAAC;AAAA,IACvB,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAUA,SAAS,kBAAkB,QAAkB;AAC3C,MAAI,MAAM,KAAK,KAAK,KAElB,IAAI,SACJ,YAAY;AAId,MAAI,WACF,KAAK,IAAI,OAAO,CAAC,CAAC,KAAK,MAAM,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,IAAI;AACzE,MAAI,KAAK;AAAA,IACP,IAAI,WAAW;AAAA,IACf,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,KAAK,OAAO,MAAM,OAAO,CAAC,IAAI,GAAG,CAAC;AAAA,EAC/D;AAGA,MAAI,GAAG,CAAC,IAAI;AAAW,OAAG,CAAC,IAAI;AAC/B,MAAI,GAAG,CAAC,IAAI,CAAC;AAAW,OAAG,CAAC,IAAI,CAAC;AACjC,MAAI,GAAG,CAAC,IAAI;AAAW,OAAG,CAAC,IAAI;AAC/B,MAAI,GAAG,CAAC,IAAI,CAAC;AAAW,OAAG,CAAC,IAAI,CAAC;AAEjC,SAAO;AACT;AAUA,SAAS,eAAe,IAAc;AAEpC,MAAI,MAAM,MAAM,KAAK;AACrB,MAAI,IAAI;AAER,SAAO;AAAA,IACJ,GAAG,CAAC,IAAI,MAAO;AAAA,KACf,KAAK,KAAK,MAAM,IAAM,KAAK,KAAK,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK;AAAA,EAC5D;AACF;AASA,SAAS,KAAK,GAAW;AACvB,SAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC;","names":[]} | ||
| {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Position } from \"geojson\";\nimport { coordEach } from \"@turf/meta\";\nimport { AllGeoJSON, isNumber } from \"@turf/helpers\";\nimport { clone } from \"@turf/clone\";\n\n/**\n * Converts a WGS84 GeoJSON object into Mercator (EPSG:900913) projection\n *\n * @function\n * @param {GeoJSON|Position} geojson WGS84 GeoJSON object\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Projected GeoJSON\n * @example\n * var pt = turf.point([-71,41]);\n * var converted = turf.toMercator(pt);\n *\n * //addToMap\n * var addToMap = [pt, converted];\n */\nfunction toMercator<G = AllGeoJSON | Position>(\n geojson: G,\n options: { mutate?: boolean } = {}\n): G {\n return convert(geojson, \"mercator\", options);\n}\n\n/**\n * Converts a Mercator (EPSG:900913) GeoJSON object into WGS84 projection\n *\n * @function\n * @param {GeoJSON|Position} geojson Mercator GeoJSON object\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Projected GeoJSON\n * @example\n * var pt = turf.point([-7903683.846322424, 5012341.663847514]);\n * var converted = turf.toWgs84(pt);\n *\n * //addToMap\n * var addToMap = [pt, converted];\n */\nfunction toWgs84<G = AllGeoJSON | Position>(\n geojson: G,\n options: { mutate?: boolean } = {}\n): G {\n return convert(geojson, \"wgs84\", options);\n}\n\n/**\n * Converts a GeoJSON coordinates to the defined `projection`\n *\n * @private\n * @param {GeoJSON} geojson GeoJSON Feature or Geometry\n * @param {string} projection defines the projection system to convert the coordinates to\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} Converted GeoJSON\n */\nfunction convert(\n geojson: any,\n projection: string,\n options: { mutate?: boolean } = {}\n): any {\n // Optional parameters\n options = options || {};\n var mutate = options.mutate;\n\n // Validation\n if (!geojson) throw new Error(\"geojson is required\");\n\n // Handle Position\n if (Array.isArray(geojson) && isNumber(geojson[0]))\n geojson =\n projection === \"mercator\"\n ? convertToMercator(geojson)\n : convertToWgs84(geojson);\n // Handle GeoJSON\n else {\n // Handle possible data mutation\n if (mutate !== true) geojson = clone(geojson);\n\n coordEach(geojson, function (coord) {\n var newCoord =\n projection === \"mercator\"\n ? convertToMercator(coord)\n : convertToWgs84(coord);\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n });\n }\n return geojson;\n}\n\n/**\n * Convert lon/lat values to 900913 x/y.\n * (from https://github.com/mapbox/sphericalmercator)\n *\n * @private\n * @param {Array<number>} lonLat WGS84 point\n * @returns {Array<number>} Mercator [x, y] point\n */\nfunction convertToMercator(lonLat: number[]) {\n var D2R = Math.PI / 180,\n // 900913 properties\n A = 6378137.0,\n MAXEXTENT = 20037508.342789244;\n\n // compensate longitudes passing the 180th meridian\n // from https://github.com/proj4js/proj4js/blob/master/lib/common/adjust_lon.js\n var adjusted =\n Math.abs(lonLat[0]) <= 180 ? lonLat[0] : lonLat[0] - sign(lonLat[0]) * 360;\n var xy = [\n A * adjusted * D2R,\n A * Math.log(Math.tan(Math.PI * 0.25 + 0.5 * lonLat[1] * D2R)),\n ];\n\n // if xy value is beyond maxextent (e.g. poles), return maxextent\n if (xy[0] > MAXEXTENT) xy[0] = MAXEXTENT;\n if (xy[0] < -MAXEXTENT) xy[0] = -MAXEXTENT;\n if (xy[1] > MAXEXTENT) xy[1] = MAXEXTENT;\n if (xy[1] < -MAXEXTENT) xy[1] = -MAXEXTENT;\n\n return xy;\n}\n\n/**\n * Convert 900913 x/y values to lon/lat.\n * (from https://github.com/mapbox/sphericalmercator)\n *\n * @private\n * @param {Array<number>} xy Mercator [x, y] point\n * @returns {Array<number>} WGS84 [lon, lat] point\n */\nfunction convertToWgs84(xy: number[]) {\n // 900913 properties.\n var R2D = 180 / Math.PI;\n var A = 6378137.0;\n\n return [\n (xy[0] * R2D) / A,\n (Math.PI * 0.5 - 2.0 * Math.atan(Math.exp(-xy[1] / A))) * R2D,\n ];\n}\n\n/**\n * Returns the sign of the input, or zero\n *\n * @private\n * @param {number} x input\n * @returns {number} -1|0|1 output\n */\nfunction sign(x: number) {\n return x < 0 ? -1 : x > 0 ? 1 : 0;\n}\n\nexport { toMercator, toWgs84 };\n"],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAqB,gBAAgB;AACrC,SAAS,aAAa;AAiBtB,SAAS,WACP,SACA,UAAgC,CAAC,GAC9B;AACH,SAAO,QAAQ,SAAS,YAAY,OAAO;AAC7C;AAiBA,SAAS,QACP,SACA,UAAgC,CAAC,GAC9B;AACH,SAA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,KAAK;AACrB,MAAI,IAAI;AAER,SAAO;AAAA,IACJ,GAAG,CAAC,IAAI,MAAO;AAAA,KACf,KAAK,KAAK,MAAM,IAAM,KAAK,KAAK,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK;AAAA,EAC5D;AACF;AASA,SAAS,KAAK,GAAW;AACvB,SAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC;","names":[]} |
+12
-12
| { | ||
| "name": "@turf/projection", | ||
| "version": "7.1.0", | ||
| "version": "7.2.0", | ||
| "description": "turf projection module", | ||
@@ -67,5 +67,5 @@ "author": "Turf Authors", | ||
| "devDependencies": { | ||
| "@turf/truncate": "^7.1.0", | ||
| "@turf/truncate": "^7.2.0", | ||
| "@types/benchmark": "^2.1.5", | ||
| "@types/tape": "^4.2.32", | ||
| "@types/tape": "^4.13.4", | ||
| "benchmark": "^2.1.4", | ||
@@ -75,16 +75,16 @@ "load-json-file": "^7.0.1", | ||
| "proj4": "^2.9.2", | ||
| "tape": "^5.7.2", | ||
| "tsup": "^8.0.1", | ||
| "tsx": "^4.6.2", | ||
| "typescript": "^5.2.2", | ||
| "tape": "^5.9.0", | ||
| "tsup": "^8.3.5", | ||
| "tsx": "^4.19.2", | ||
| "typescript": "^5.5.4", | ||
| "write-json-file": "^5.0.0" | ||
| }, | ||
| "dependencies": { | ||
| "@turf/clone": "^7.1.0", | ||
| "@turf/helpers": "^7.1.0", | ||
| "@turf/meta": "^7.1.0", | ||
| "@turf/clone": "^7.2.0", | ||
| "@turf/helpers": "^7.2.0", | ||
| "@turf/meta": "^7.2.0", | ||
| "@types/geojson": "^7946.0.10", | ||
| "tslib": "^2.6.2" | ||
| "tslib": "^2.8.1" | ||
| }, | ||
| "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef" | ||
| "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867" | ||
| } |
+2
-2
@@ -12,3 +12,3 @@ # @turf/projection | ||
| * `geojson` **([GeoJSON][1] | [Position][2])** WGS84 GeoJSON object | ||
| * `options` **[Object][3]?** Optional parameters | ||
| * `options` **[Object][3]?** Optional parameters (optional, default `{}`) | ||
@@ -36,3 +36,3 @@ * `options.mutate` **[boolean][4]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
| * `geojson` **([GeoJSON][1] | [Position][2])** Mercator GeoJSON object | ||
| * `options` **[Object][3]?** Optional parameters | ||
| * `options` **[Object][3]?** Optional parameters (optional, default `{}`) | ||
@@ -39,0 +39,0 @@ * `options.mutate` **[boolean][4]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) |
25388
4.68%144
-7.69%Updated
Updated
Updated
Updated