Closed wasa4587 closed 8 years ago
ok let me look into it
(edited your comment, fyi the back ticks can be used for multi line code samples)
um so I'm shocked your query actually works as your point is located outside of the bounding box, but once I adjust things then the following code works
var Pouch = require('pouchdb');
var Spatial = require('./');
Pouch.plugin(Spatial);
var localDB = new Pouch('./local/test');
localDB.put({ _id: '_design/foo', spatial: { bar: function (doc) { if(doc.type=='item') emit(doc.geometry); }.toString() } }).then(function () {
console.log('put design');
return localDB.post({geometry: { type: "Point", coordinates: [20.8215207, -102.76524380000001] },type:'item'})
}).then(function () {
console.log('put point');
return localDB.spatial( 'foo/bar', [ 20, -103, 21, -102 ]);
}).then(function (resp) {
console.log('query 1');
console.log(resp);
return localDB.spatial( 'foo/bar', [ 20, -103, 21, -102 ])
}).then(function (resp) {
console.log('query 2');
console.log(resp);
}).catch(function(err) {
console.log('err')
console.log(err)
});
can you provide some details of what your setup is that leads to this?
Thanks for answering.
I'm using this on ionic framework project. It's interesting, your code works well. Seems it works when you just post an item, and it only shows the item you posted.
i built the geopouch for using on browser
<!-- index.html -->
<script src="lib/pouchdb/dist/pouchdb.min.js"></script>
<script src="lib/geopouch/geopouch.js"></script>
then every request, it return only 1 item, and i think it shuold returns an incremental numer of items (first request 1 item, 2nd request 2 items, so on)
// app.js
var localDB = new PouchDB("test");
PouchDB.plugin(geopouch);
//localDB.put({ _id: '_design/foo', spatial: { bar: function (doc) { if(doc.type=='item') emit(doc.geometry); }.toString() } })
localDB.post({geometry: { type: "Point", coordinates: [20.8215207, -102.76524380000001] },type:'item'}).then(function () {
console.log('put point');
return localDB.spatial( 'foo/bar', [ 20, -103, 21, -102 ]);
}).then(function (resp) {
console.log('query 1');
console.log(resp);
return localDB.spatial( 'foo/bar', [ 20, -103, 21, -102 ])
}).then(function (resp) {
console.log('query 2');
console.log(resp);
}).catch(function(err) {
console.log('err')
console.log(err)
});
hm looks like it's picking up the previous index, looking into it
yeah there was a problem in how it reopened databases in a dep, fixed the dep and published a new version of the dep, about to publish a new version of geopouch that relies on that version including the build version of the library
done
thank you @calvinmetcalf
I create the test design doc
Then insert a dummy Point
First Query, works!
when i run the last query again, it returns an empty array
[]
Windows 8.1, Google Chrome 52.0.2743.116 m
On Firefox 47.0.1, it returns
Using a tmp view works well