bbox2extent
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -5,2 +5,12 @@ # bbox2extent change log | ||
## 1.1.0 | ||
### Added | ||
* add support for reverse operation ([#2](https://github.com/ngoldman/bbox2extent/issues/2)) | ||
* add tests | ||
* add CONTRIBUTING.md | ||
### Fixed | ||
* add better error handling for non-callback style | ||
## 1.0.1 | ||
@@ -7,0 +17,0 @@ * fix usage error in readme |
50
index.js
@@ -1,23 +0,47 @@ | ||
module.exports = function (bbox, callback) { | ||
module.exports = bbox2extent | ||
function bbox2extent (bbox, callback) { | ||
var isArray = Object.prototype.toString.call(bbox) === '[object Array]' | ||
var isLongEnough = bbox.length === 4 | ||
var isValid = bbox.length === 4 | ||
if (!isArray || !isLongEnough) { | ||
var err = 'invalid bbox object' | ||
return callback(err) | ||
if (!isArray || !isValid) { | ||
var err = 'invalid bbox array' | ||
if (callback) return callback(err) | ||
else return console.error(err) | ||
} | ||
var extent = { | ||
'xmin': bbox[0], | ||
'ymin': bbox[1], | ||
'xmax': bbox[2], | ||
'ymax': bbox[3], | ||
'spatialReference': { | ||
'wkid': 4326, | ||
'latestWkid': 4326 | ||
xmin: bbox[0], | ||
ymin: bbox[1], | ||
xmax: bbox[2], | ||
ymax: bbox[3], | ||
spatialReference: { | ||
wkid: 4326, | ||
latestWkid: 4326 | ||
} | ||
} | ||
if (callback) callback(null, extent) | ||
if (callback) return callback(null, extent) | ||
else return extent | ||
} | ||
function extent2bbox (extent, callback) { | ||
var isObject = Object.prototype.toString.call(extent) === '[object Object]' | ||
var isValid = extent.xmin !== undefined && | ||
extent.ymin !== undefined && | ||
extent.xmax !== undefined && | ||
extent.ymax !== undefined | ||
if (!isObject || !isValid) { | ||
var err = 'invalid extent object' | ||
if (callback) return callback(err) | ||
else return console.error(err) | ||
} | ||
var bbox = [extent.xmin, extent.ymin, extent.xmax, extent.ymax] | ||
if (callback) return callback(null, bbox) | ||
else return bbox | ||
} | ||
bbox2extent.reverse = extent2bbox |
{ | ||
"name": "bbox2extent", | ||
"description": "Transform a GeoJSON bounding box into an Esri-formatted extent object.", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"author": "Nate Goldman <nate@ngoldman.me>", | ||
@@ -25,7 +25,9 @@ "bugs": { | ||
"scripts": { | ||
"test": "standard" | ||
"test": "standard && node test | tap-spec" | ||
}, | ||
"devDependencies": { | ||
"standard": "^3.2.0" | ||
"standard": "^3.3.0", | ||
"tap-spec": "^2.2.2", | ||
"tape": "^3.5.0" | ||
} | ||
} |
@@ -39,4 +39,40 @@ # bbox2extent | ||
Also supports reverse operation (converting an extent to a bounding box) via `reverse`: | ||
```js | ||
var extent2bbox = require('bbox2extent').reverse | ||
var extent = { | ||
xmin: -108.9395, | ||
ymin: 37.084968, | ||
xmax: -102, | ||
ymax: 40.8877, | ||
spatialReference: { | ||
wkid: 4326, | ||
latestWkid: 4326 | ||
} | ||
} | ||
var bbox = extent2bbox(extent) | ||
// [ -108.9395, 37.084968, -102, 40.8877 ] | ||
// OR | ||
extent2bbox(extent, function (err, bbox) { | ||
if (err) throw err | ||
console.log(bbox) | ||
// [ -108.9395, 37.084968, -102, 40.8877 ] | ||
}) | ||
``` | ||
## Contributing | ||
`bbox2extent` is an **OPEN Open Source Project**. This means that: | ||
> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project. | ||
See the [CONTRIBUTING.md](CONTRIBUTING.md) file for more details. | ||
## License | ||
[ISC](LICENSE.md) |
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
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
7131
9
79
78
3