1 | ![](http://img.shields.io/travis/mapbox/geojson-extent.svg?style=flat)
|
2 |
|
3 | # geojson-extent
|
4 |
|
5 | Compute an extent given a GeoJSON object.
|
6 |
|
7 | ## install
|
8 |
|
9 | npm install --save geojson-extent
|
10 |
|
11 | ## example
|
12 |
|
13 | [Live example with Mapbox Static Map API](https://www.mapbox.com/mapbox.js/example/v1.0.0/static-map-from-geojson-with-geo-viewport/)
|
14 |
|
15 | ```js
|
16 | var geojsonExtent = require('geojson-extent');
|
17 |
|
18 | geojsonExtent({ type: 'Point', coordinates: [0, 0] }); // returns 0,0,0,0 extent
|
19 | ```
|
20 |
|
21 | ## bin
|
22 |
|
23 | Provides a binary that takes GeoJSON as stdin and returns a JSON stringified
|
24 | array of extent data.
|
25 |
|
26 | ```sh
|
27 | $ npm install -g geojson-extent
|
28 | $ geojson-extent < file.geojson
|
29 | ```
|
30 |
|
31 | Given an argument of `leaflet`, this will return Leaflet-formatted data instead.
|
32 |
|
33 | ```sh
|
34 | $ geojson-extent leaflet < file.geojson
|
35 | ```
|
36 |
|
37 | ## api
|
38 |
|
39 | ### `extent(geojson)`
|
40 |
|
41 | Given any valid GeoJSON object, return bounds in the form `[WSEN]`.
|
42 | Invalid objects will return `null`.
|
43 |
|
44 | ### `extent.polygon(geojson)`
|
45 |
|
46 | Given any valid GeoJSON object, return bounds in the form of a GeoJSON polygon object.
|
47 | Invalid objects will return `null`.
|
48 |
|
49 | ### `extent.bboxify(geojson)`
|
50 |
|
51 | Add [bounding boxes](http://geojson.org/geojson-spec.html#bounding-boxes) to all
|
52 | appropriate GeoJSON objects - Feature, FeatureCollection, and Geometry.
|