Skip to content

Commit

Permalink
adding a multi test and wrapping geoms in arrays to normalize ring co…
Browse files Browse the repository at this point in the history
…unts
  • Loading branch information
chelm committed Mar 20, 2015
1 parent 7cebbb0 commit aea084b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ module.exports = function (collection, callback) {

if (isPoint || isMultiPoint) {
if (isPoint) coords = [[[coords]]]
else coords = [[coords]]
loop(bbox, coords)
}

if (isLine || isMultiLine) {
if (isLine) coords = [[coords]]
else coords = [coords]
loop(bbox, coords)
}

Expand All @@ -39,9 +41,11 @@ module.exports = function (collection, callback) {
}

function loop (bbox, coords) {
coords.forEach(function (r, j) {
r[0].forEach(function (c, k) {
extend(bbox, c)
coords.forEach(function (r) {
r.forEach(function (inner) {
inner.forEach(function (c) {
extend(bbox, c)
})
})
})
}
Expand Down
21 changes: 21 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var esriExtent = require('..')
var example = require('./geojson-spec-example.json')
var exampleMulti = require('./geojson-multi-spec-example.json')
var test = require('tape')
var expected = {
xmin: 100,
Expand All @@ -12,6 +13,17 @@ var expected = {
}
}

var expectedMulti = {
xmin: 98,
ymin: 0,
xmax: 107,
ymax: 2,
spatialReference: {
wkid: 4326,
latestWkid: 4326
}
}

test('get correct extent from geojson spec example', function (t) {
esriExtent(example, function (err, extent) {
if (err) throw err
Expand All @@ -20,3 +32,12 @@ test('get correct extent from geojson spec example', function (t) {
t.end()
})
})

test('get correct extent from geojson multi spec example', function (t) {
esriExtent(exampleMulti, function (err, extent) {
if (err) throw err

t.deepEqual(extent, expectedMulti)
t.end()
})
})

0 comments on commit aea084b

Please sign in to comment.