2
* Given a GeoJSON object, returns the corresponding bounding box. The bounding
3
* box is represented by a two-dimensional array: [[left, bottom], [right,
4
* top]], where left is the minimum longitude, bottom is the minimum latitude,
5
* right is maximum longitude, and top is the maximum latitude.
7
d3.geo.bounds = function(feature) {
12
d3_geo_bounds(feature, function(x, y) {
13
if (x < left) left = x;
14
if (x > right) right = x;
15
if (y < bottom) bottom = y;
18
return [[left, bottom], [right, top]];
21
function d3_geo_bounds(o, f) {
22
if (d3_geo_boundsTypes.hasOwnProperty(o.type)) d3_geo_boundsTypes[o.type](o, f);
25
var d3_geo_boundsTypes = {
26
Feature: d3_geo_boundsFeature,
27
FeatureCollection: d3_geo_boundsFeatureCollection,
28
GeometryCollection: d3_geo_boundsGeometryCollection,
29
LineString: d3_geo_boundsLineString,
30
MultiLineString: d3_geo_boundsMultiLineString,
31
MultiPoint: d3_geo_boundsLineString,
32
MultiPolygon: d3_geo_boundsMultiPolygon,
33
Point: d3_geo_boundsPoint,
34
Polygon: d3_geo_boundsPolygon
37
function d3_geo_boundsFeature(o, f) {
38
d3_geo_bounds(o.geometry, f);
41
function d3_geo_boundsFeatureCollection(o, f) {
42
for (var a = o.features, i = 0, n = a.length; i < n; i++) {
43
d3_geo_bounds(a[i].geometry, f);
47
function d3_geo_boundsGeometryCollection(o, f) {
48
for (var a = o.geometries, i = 0, n = a.length; i < n; i++) {
49
d3_geo_bounds(a[i], f);
53
function d3_geo_boundsLineString(o, f) {
54
for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
59
function d3_geo_boundsMultiLineString(o, f) {
60
for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
61
for (var b = a[i], j = 0, m = b.length; j < m; j++) {
67
function d3_geo_boundsMultiPolygon(o, f) {
68
for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
69
for (var b = a[i][0], j = 0, m = b.length; j < m; j++) {
75
function d3_geo_boundsPoint(o, f) {
76
f.apply(null, o.coordinates);
79
function d3_geo_boundsPolygon(o, f) {
80
for (var a = o.coordinates[0], i = 0, n = a.length; i < n; i++) {