From 041090ce6b557fbbc9bdc290852a75ae492a09f5 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 3 Feb 2014 09:02:31 -0500 Subject: [PATCH] (#1) - more documentation, maybe a build step --- index.js | 23 +++++++++++------------ package.json | 12 +++++++----- readme.md | 7 ++++++- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index ab3319f..26bcdda 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,7 @@ function normalizeKey(key) { key: newKey, geometry: geometry }; -}; +} function within(key, start_range, end_range) { var start; var end; @@ -47,21 +47,20 @@ function within(key, start_range, end_range) { 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); @@ -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 @@ -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){ @@ -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); @@ -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]; @@ -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() { }; diff --git a/package.json b/package.json index e9d0197..49329e6 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/readme.md b/readme.md index 6ad98b9..db2bcc6 100644 --- a/readme.md +++ b/readme.md @@ -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` \ No newline at end of file +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)];` \ No newline at end of file