Skip to content

Commit

Permalink
finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Jan 14, 2015
1 parent 0c0b0a0 commit f3f31d1
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 192 deletions.
36 changes: 33 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,42 @@ function spatial(fun, bbox, opts, cb, /*only needed if people use 2 bboxen-->*/c
var i = 0;
function emit(doc) {
if (i++) {
emited.push(store.append(id , calculatebounds(doc)));
emited.push(store.append(id, calculatebounds(doc)));
} else {
emited.push(store.insert(id , calculatebounds(doc)));
emited.push(store.insert(id, calculatebounds(doc)));
}
}
func(doc, emit);
function fixMulti (doc) {
var type = doc.type;
switch (type) {
case 'MultiPoint':
return doc.coordinates.forEach(function (coord) {
emit({
type: 'Point',
coordinates: coord
});
});
case 'MultiLineString':
return doc.coordinates.forEach(function (coord) {
emit({
type: 'LineString',
coordinates: coord
});
});
case 'MultiPolygon':
return doc.coordinates.forEach(function (coord) {
emit({
type: 'Polygon',
coordinates: coord
});
});
case 'GeometryCollection':
return doc.geometries.forEach(fixMulti);
default:
return emit(doc);
}
}
func(doc, fixMulti);
return Promise.all(emited);
}
var lastSeq;
Expand Down
7 changes: 4 additions & 3 deletions store.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ Store.prototype.del = function(key, cb) {
var self = this;
this.db.get(key).then(function (doc) {
return self.db.remove(doc);
}).then(function () {
}).then(function (r) {
cb();
}, cb);
}, function (e) {
cb(e);
});
};
Store.prototype.batch = function(array, cb) {
var self = this;

return Promise.all(array.map(function (item) {
return new Promise(function (resolve, reject) {
function callback(err, value) {
Expand Down
Loading

0 comments on commit f3f31d1

Please sign in to comment.