UNPKG

1.26 kBMarkdownView Raw
1![](http://img.shields.io/travis/mapbox/geojson-extent.svg?style=flat)
2
3# geojson-extent
4
5Compute 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
16var geojsonExtent = require('geojson-extent');
17
18geojsonExtent({ type: 'Point', coordinates: [0, 0] }); // returns 0,0,0,0 extent
19```
20
21## bin
22
23Provides a binary that takes GeoJSON as stdin and returns a JSON stringified
24array of extent data.
25
26```sh
27$ npm install -g geojson-extent
28$ geojson-extent < file.geojson
29```
30
31Given 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
41Given any valid GeoJSON object, return bounds in the form `[WSEN]`.
42Invalid objects will return `null`.
43
44### `extent.polygon(geojson)`
45
46Given any valid GeoJSON object, return bounds in the form of a GeoJSON polygon object.
47Invalid objects will return `null`.
48
49### `extent.bboxify(geojson)`
50
51Add [bounding boxes](http://geojson.org/geojson-spec.html#bounding-boxes) to all
52appropriate GeoJSON objects - Feature, FeatureCollection, and Geometry.