geojson-extent
Advanced tools
Comparing version 0.2.0 to 0.3.0
10
index.js
var geojsonCoords = require('geojson-coords'), | ||
traverse = require('traverse'), | ||
extent = require('extent'); | ||
@@ -12,2 +13,11 @@ | ||
module.exports.bboxify = function(_) { | ||
return traverse(_).map(function(value) { | ||
if (value && typeof value.type === 'string') { | ||
value.bbox = getExtent(value).bbox(); | ||
this.update(value); | ||
} | ||
}); | ||
}; | ||
function getExtent(_) { | ||
@@ -14,0 +24,0 @@ var bbox = [Infinity, Infinity, -Infinity, -Infinity], |
{ | ||
"name": "geojson-extent", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "compute the bounding box of geojson features", | ||
@@ -34,3 +34,4 @@ "main": "index.js", | ||
"geojson-coords": "0.0.0", | ||
"rw": "~0.1.4" | ||
"rw": "~0.1.4", | ||
"traverse": "~0.6.6" | ||
}, | ||
@@ -37,0 +38,0 @@ "devDependencies": { |
@@ -48,1 +48,6 @@ ![](http://img.shields.io/travis/mapbox/geojson-extent.svg?style=flat) | ||
Invalid objects will return `null`. | ||
### `extent.bboxify(geojson)` | ||
Add [bounding boxes](http://geojson.org/geojson-spec.html#bounding-boxes) to all | ||
appropriate GeoJSON objects - Feature, FeatureCollection, and Geometry. |
@@ -14,2 +14,171 @@ var test = require('tap').test, | ||
test('bboxify', function(t) { | ||
t.deepEqual(geojsonExtent.bboxify({ | ||
type: 'Point', | ||
coordinates: [0, 0] | ||
}), { | ||
type: 'Point', | ||
coordinates: [0, 0], | ||
bbox: [0, 0, 0, 0] | ||
}, 'a single point'); | ||
t.deepEqual(geojsonExtent.bboxify({ "type": "FeatureCollection", | ||
"features": [ | ||
{ "type": "Feature", | ||
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, | ||
"properties": {"prop0": "value0"} | ||
}, | ||
{ "type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}, | ||
{ "type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], | ||
[100.0, 1.0], [100.0, 0.0] ] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": {"this": "that"} | ||
} | ||
} | ||
] | ||
}), { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"properties": { | ||
"prop0": "value0" | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
102, | ||
0.5 | ||
], | ||
"bbox": [ | ||
102, | ||
0.5, | ||
102, | ||
0.5 | ||
] | ||
}, | ||
"bbox": [ | ||
102, | ||
0.5, | ||
102, | ||
0.5 | ||
] | ||
}, | ||
{ | ||
"type": "Feature", | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0 | ||
}, | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[ | ||
102, | ||
0 | ||
], | ||
[ | ||
103, | ||
1 | ||
], | ||
[ | ||
104, | ||
0 | ||
], | ||
[ | ||
105, | ||
1 | ||
] | ||
], | ||
"bbox": [ | ||
102, | ||
0, | ||
105, | ||
1 | ||
] | ||
}, | ||
"bbox": [ | ||
102, | ||
0, | ||
105, | ||
1 | ||
] | ||
}, | ||
{ | ||
"type": "Feature", | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": { | ||
"this": "that" | ||
} | ||
}, | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[ | ||
100, | ||
0 | ||
], | ||
[ | ||
101, | ||
0 | ||
], | ||
[ | ||
101, | ||
1 | ||
], | ||
[ | ||
100, | ||
1 | ||
], | ||
[ | ||
100, | ||
0 | ||
] | ||
] | ||
], | ||
"bbox": [ | ||
100, | ||
0, | ||
101, | ||
1 | ||
] | ||
}, | ||
"bbox": [ | ||
100, | ||
0, | ||
101, | ||
1 | ||
] | ||
} | ||
], | ||
"bbox": [ | ||
100, | ||
0, | ||
105, | ||
1 | ||
] | ||
}, 'a single point'); | ||
t.end(); | ||
}); | ||
test('extent', function(t) { | ||
@@ -16,0 +185,0 @@ t.deepEqual(geojsonExtent({ |
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
13696
270
53
4
+ Addedtraverse@~0.6.6
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedarraybuffer.prototype.slice@1.0.3(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddata-view-buffer@1.0.1(transitive)
+ Addeddata-view-byte-length@1.0.1(transitive)
+ Addeddata-view-byte-offset@1.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedes-abstract@1.23.5(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedes-set-tostringtag@2.0.3(transitive)
+ Addedes-to-primitive@1.2.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction.prototype.name@1.1.6(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedget-symbol-description@1.0.2(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-data-view@1.0.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-negative-zero@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-weakref@1.0.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedregexp.prototype.flags@1.5.3(transitive)
+ Addedsafe-array-concat@1.1.2(transitive)
+ Addedsafe-regex-test@1.0.3(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstring.prototype.trim@1.2.9(transitive)
+ Addedstring.prototype.trimend@1.0.8(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedtraverse@0.6.10(transitive)
+ Addedtyped-array-buffer@1.0.2(transitive)
+ Addedtyped-array-byte-length@1.0.1(transitive)
+ Addedtyped-array-byte-offset@1.0.2(transitive)
+ Addedtyped-array-length@1.0.6(transitive)
+ Addedtypedarray.prototype.slice@1.0.3(transitive)
+ Addedunbox-primitive@1.0.2(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)