Skip to content

Commit

Permalink
(#1) - more documentation, maybe a build step
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Feb 28, 2014
1 parent 9186ca4 commit 041090c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
23 changes: 11 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,28 @@ function normalizeKey(key) {
key: newKey,
geometry: geometry
};
};
}
function within(key, start_range, end_range) {
var start;
var end;
for(var i=0; i<key.length; i++) {
start = key[i][0];
end = key[i][1];
if (
((start_range[i] === null && (start <= end_range[i] || end_range[i] === null))
((start_range[i] === null && (start <= end_range[i] || end_range[i] === null)) ||
// Start is set
|| (start <= end_range[i] || end_range[i] === null))
&&
(start <= end_range[i] || end_range[i] === null)) &&
// Wildcard at the end
((end_range[i] === null && (end >= start_range[i] || start_range[i] === null))
((end_range[i] === null && (end >= start_range[i] || start_range[i] === null)) ||
// End is set
|| (end >= start_range[i] || start_range[i] === null))) {
(end >= start_range[i] || start_range[i] === null))) {
continue;
} else {
return false;
}
}
return true;
};
}
function Spatial(db) {
if(!(this instanceof Spatial)){
return new Spatial(db);
Expand Down Expand Up @@ -107,7 +106,7 @@ function Spatial(db) {
}
}
results.push(viewRow);
};
}

// ugly way to make sure references to 'emit' in map/reduce bind to the
// above emit
Expand Down Expand Up @@ -185,7 +184,7 @@ function Spatial(db) {
opts = {};
}
callback = callback || function(){};
opts = opts||{}
opts = opts||{};
var result;
if (typeof fun !== 'string') {
result = promise(function(success,failure){
Expand All @@ -202,7 +201,7 @@ function Spatial(db) {
callback(null,resp);
},callback);
return result;
}
};
function spatialQuery(fun, opts) {
if (db.type() === 'http') {
return httpQuery(fun, opts);
Expand All @@ -213,7 +212,7 @@ function Spatial(db) {
return viewQuery(doc.spatial[parts[1]], opts);
});
}
};
}
function rotateCoords(coords){
var mins = coords[0];
var maxs = coords[1];
Expand All @@ -224,7 +223,7 @@ function rotateCoords(coords){
// Store it in the Spatial object, so we can test it
Spatial.calculateBbox = function(coords){
return rotateCoords(calculateBbox(coords));
}
};
// Deletion is a noop since we dont store the results of the view
Spatial._delete = function() { };

Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"url": "git://github.com/calvinmetcalf/geopouch.git"
},
"scripts": {
"test": "./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js"
"test": "./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js",
"build": "mkdir -p dist && browserify index.js -s geopouch -o dist/geopouch.js"
},
"keywords": [
"geospatial",
Expand All @@ -22,14 +23,15 @@
"url": "https://github.com/calvinmetcalf/geopouch/issues"
},
"dependencies": {
"lie-denodify": "~0.1.1",
"lie": "~2.3.0",
"geojson-bounding-volume": "~0.1.1"
"geojson-bounding-volume": "~0.1.1",
"lie-denodify": "~0.1.2",
"lie": "~2.5.3"
},
"devDependencies": {
"chai": "~1.8.1",
"mocha": "~1.14.0",
"pouchdb": "0.0.14",
"istanbul": "~0.1.45"
"istanbul": "~0.1.45",
"browserify": "~3.24.11"
}
}
7 changes: 6 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ Spatial plugin from PouchDB extracted and supporting N dimentional coordinates.

Origionally by [@vmx](https://github.com/) with contribution by [@daleharvey](https://github.com/) and [@calvinmetcalf](https://github.com/).

Test with `npm test` coverage report with `npm test --coverage`
Test with `npm test` coverage report with `npm test --coverage`, build with `npm run build`. Server queries require geocouch installed, have yet to test with that.

API
====

`db.spatial([xmin, ymin, xmax, ymax], [options, callback)];`

0 comments on commit 041090c

Please sign in to comment.